Push Notifications
How masto handles notifications!
Description
- An account (usually through an app) will create a push notification subscription using the
/api/v1/push/subscription
endpoint - When an activitypub event triggers a notification like a like, mention, etc., it will use a
LocalNotificationWorker
to callNotifyService
- The
NotifyService
dispatches the notification to the web Streaming system (if the account is logged in on the website), and then to thePushNotificationWorker
- The
PushNotificationWorker
then attempts to push the notification with- 5 retries
- 48 hour TTL
Usage
Deleting a Push Subscription
Sometimes push subscriptions can get broken and masto doesn't handle this all too well.
Each push subscription is per app authorized on an account, rather than per account. This makes it impossible (as far as I can tell) to delete the subscription manually using the API - you usually can't get the app's access token or client id/secrets.
You can go to https://neuromatch.social/oauth/authorized_applications and revoke access for that app with the broken notifs, and then re-log in with it, and that should clear the broken notification object.
Implementation
Like much of the rest of masto, it uses a rail model/controller system for its api.
- API endpoint:
/api/v1/push/subscription
- Controller:
SubscriptionsController
- Model:
PushSubsription
- Workers:
PushNotificationWorker
andLocalNotificationWorker
- Service:
NotifyService
- Spec (tests)
- Notification Triggers - all the activitypub activities!