Push Notifications using UnifiedPush #35

Open
opened 2026-06-03 10:47:23 -04:00 by Henry-Hiles · 1 comment
Owner

Using this commit to detail what's needed for push notifications.

Essentially, the easiest way by far would be by using MSC4174 (Web Push), so I would like to wait for this. Otherwise, we would need to host an NTFY or similar.

An alternative, of course, is keeping the app running in the background, but I'd like to avoid this.

Using this commit to detail what's needed for push notifications. Essentially, the easiest way by far would be by using [MSC4174 (Web Push)](https://github.com/matrix-org/matrix-spec-proposals/pull/4174), so I would like to wait for this. Otherwise, we would need to host an NTFY or similar. An alternative, of course, is keeping the app running in the background, but I'd like to avoid this.
Author
Owner

Okay, I've thought about how this would work, and I'm recording my thoughts here. I definitely want to use Web Push.

I believe how everything works is:

Registration

  1. We register with a local distributor using UnifiedPush. From this source in UnifiedPush docs, it seems like since MSC3174 includes VAPID support, we can support FCM by simply adding a dependency to the FCM distributor in build.gradle:
dependencies {
    // ...
    implementation 'org.unifiedpush.android:embedded-fcm-distributor:{VERSION}'
  1. We register with the server as a pusher (/_matrix/client/v3/pushers/set)
  2. We receive a push notification encrypted and authenticated with VAPID as a confirmation, e.g.:
{
	"app_id": "nexus.federated.Nexus",
	"ack_token": "6fc76b70-5fad-4eb7-93ea-a1af7a03258b"
}

We POST to /_matrix/client/v3/pushers/ack with the app_id and ack_token parameters that we got earlier. This activates the pusher, for future use.

Receiving Notifications

  1. The distributor receives notifications following the Push Gateway Spec, but encrypted. When it gets these, it opens Nexus in the background.
  2. We use ClientController.getEvent to fetch the event, and check Event.unreadType. If it's at least UnreadType.notify, we send a system notification, probably using flutter_local_notifications. I suppose when we support calls, if the notification is a call, we pop up with a call UI.
  3. The app quits, as it has now sent the notification.

Recording past notifications

We can probably use Room.notifications aggregated from all rooms to create a global "Notifications" page. If this doesn't work, we can also record notifications ourselves on the receival step.

Acting upon notifications

  1. When the user taps on a notification, the app opens to the notifications page, ideally scrolled to the correct notification. This should be easy enough using getNotificationAppLaunchDetails from flutter_local_notifications, though we may have to register with DBus on Linux.
Okay, I've thought about how this would work, and I'm recording my thoughts here. I definitely want to use Web Push. I believe how everything works is: ## Registration 1. We register with a local distributor using [UnifiedPush](https://pub.dev/packages/unifiedpush). From [this source in UnifiedPush docs](https://unifiedpush.org/kdoc/embedded_fcm_distributor/), it seems like since MSC3174 includes VAPID support, we can support FCM by simply adding a dependency to the FCM distributor in `build.gradle`: ```gradle dependencies { // ... implementation 'org.unifiedpush.android:embedded-fcm-distributor:{VERSION}' ``` 2. We register with the server as a pusher (`/_matrix/client/v3/pushers/set`) 3. We receive a push notification encrypted and authenticated with VAPID as a confirmation, e.g.: ```json { "app_id": "nexus.federated.Nexus", "ack_token": "6fc76b70-5fad-4eb7-93ea-a1af7a03258b" } ``` We `POST` to `/_matrix/client/v3/pushers/ack` with the `app_id` and `ack_token` parameters that we got earlier. This activates the pusher, for future use. ## Receiving Notifications 1. The distributor receives notifications following the [Push Gateway Spec](https://spec.matrix.org/v1.18/push-gateway-api/), but [encrypted](https://github.com/p1gp1g/matrix-spec-proposals/blob/webpush-pushkind/proposals/4174-webpush-pushkind.md#content-of-the-push-notifications). When it gets these, it opens Nexus in the background. 2. We use `ClientController.getEvent` to fetch the event, and check `Event.unreadType`. If it's at least `UnreadType.notify`, we send a system notification, probably using [flutter_local_notifications](https://pub.dev/packages/flutter_local_notifications). I suppose when we support calls, if the notification is a call, we pop up with a call UI. 3. The app quits, as it has now sent the notification. ## Recording past notifications We can probably use `Room.notifications` aggregated from all rooms to create a global "Notifications" page. If this doesn't work, we can also record notifications ourselves on the receival step. ## Acting upon notifications 1. When the user taps on a notification, the app opens to the notifications page, ideally scrolled to the correct notification. This should be easy enough using `getNotificationAppLaunchDetails` from [flutter_local_notifications](https://pub.dev/packages/flutter_local_notifications), though we may have to register with DBus on Linux.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Nexus/nexus#35
No description provided.