Support for push notifications in GotoSocial 0.18
I'm the GotoSocial developer implementing Web Push notifications for the upcoming GtS 0.18 release and wanted to give you a heads up. Right now Elk properly displays that GtS doesn't support them yet:
But we'll be adding them with superseriousbusiness/gotosocial#3587 fairly soon. They work almost identically to Mastodon's, with the following caveats:
- We have a few additional notification types for GotoSocial interaction policies:
pending.favourite,pending.reply, andpending.reblog -
policyfor controlling who you get PNs from is not yet implemented: you can set it to anything but GtS will ignore it and always returnpolicy: "all"(this may change before we ship 0.18)
Please let me know if you have questions.
Thanks for sharing the update. 😃 I'm still unfamiliar with how push notification works in Mastodon but I checked some related codes.
Message
In the current implementation, the second paragraph (It seems that your server does not...) is shown when currentUser object has vapidKey value. If the new version has the same property, it will be hidden. Otherwise, we'll need to adjust the feature detection.
ref.
- https://github.com/elk-zone/elk/blob/main/components/notification/NotificationEnablePushNotification.client.vue#L18
- https://github.com/elk-zone/elk/blob/main/components/notification/NotificationEnablePushNotification.client.vue#L59-L61
New notification type
We have a few additional notification types for GotoSocial interaction policies: pending.favourite, pending.reply, and pending.reblog
Current Canary Elk won't show notifications with unknown types in Notification tab (https://main.elk.zone/notifications), and just print out warnings to the console: https://github.com/elk-zone/elk/blob/main/components/notification/NotificationCard.vue#L34 Once Goto Social updates, we could add those types with new strings if needed.
Do you happen to know where the VAPID key is coming from?
VAPID public keys are per instance, but Mastodon used to also send them when app credentials were created; this was deprecated in Mastodon 4.3.0 and may stop working someday.
Since Mastodon 4.3.0, it's now available from the v2 instance API. You can see that in the GtS version of my own push-notification-enabled GtS server here: https://princess.industries/api/v2/instance
Finally, it's available on Web Push subscription objects, but that's probably not relevant to this case, since you'd need to create a subscription to get it that way, and this check happens before that.
Let me confirm that we're providing it all three ways in GtS and get back to you.
can you check the error in devtools? the server key is requested when the user signs-in:
https://github.com/elk-zone/elk/blob/a7d64fd1329c6299799487f20f3783598a774460/composables/users.ts#L106
Here the api: https://docs.joinmastodon.org/methods/push/#get
And the vapid_key logic here:
https://github.com/elk-zone/elk/blob/a7d64fd1329c6299799487f20f3783598a774460/composables/push-notifications/createPushSubscription.ts#L19-L38
and the creation here:
https://github.com/elk-zone/elk/blob/a7d64fd1329c6299799487f20f3783598a774460/composables/push-notifications/createPushSubscription.ts#L118-L135
Do you have enabled another account with psuh notifications enabled? do you have permissions blocked (push notification requires you to enable browser push notifications when asked)?
I don't have permissions blocked, and I don't have another account with push notifications enabled (I'm aware that a given site can only have one push subscription at a time).
As far as errors, both Mastodon and GtS 404 when /api/v1/push/subscription is called, but this is expected because no push subscription exists when you've just logged in for the first time.
I think we're running into #2562 here: elk.zone has old OAuth app credentials for my production and test servers, and those credentials don't have an associated VAPID key. If you can delete your stored app credentials for princess.industries and haruko.org, we can test that theory. Unfortunately, I don't have any more instances I can use for testing this theory, but I did manage to break logging into haruko.org entirely by deleting credentials for Elk before I saw that bug.
I believe there are at least two possible fixes aside from directly addressing #2562; one is to do a one-time invalidation of the app token for every GtS instance, and the other is to use the VAPID key in /api/v2/instance for detecting Web Push support, instead of the VAPID key returned when app credentials are created.
Thanks for the suggestions. I'm going to take a closer look at this issue this week and try to understand how push notifications work.
I was able to set up GoToSocial server on my Raspberry Pi with docker-compose (https://dev-000.gotosocial.shuuji3.xyz/@shuuji3) so that I can check how they interact with the local Elk dev server. Can I use snapshot tag image for testing this? I assume it includes the latest PR for a push notification (https://github.com/superseriousbusiness/gotosocial/pull/3721).
I think the first step I can try is to implement the second option, using /api/v2/instance's configurations.vapid.secret_key to detect availability for push notification.
#2562 was also a long-standing issue and I understand we need to fix it at some point. After implementing that, I'll try TTL cache package (like https://www.npmjs.com/package/@isaacs/ttlcache) or something to prevent permanent lockout from Elk.
Another idea for testing: maybe you can create a PR (with a trivial edit) against this repository just for testing. Elk repository will create a new deploy preview using Netlify similar to the production build, and it issues a new domain for each PR.
For example, the creation of this PR https://github.com/elk-zone/elk/pull/3183 triggered the new deploy preview with this URL: https://deploy-preview-3183--elk-zone.netlify.app/.
It should have a clean database for each Elk server so the old OAuth app credentials don't exist there. If you think it works for you, please feel free to create any number of PR 🙂
@shuuji3 that's correct, the snapshot Docker release should be updated every time we merge to main.
Probably #3193 will (partially) solve the app token issue. It prioritizes using vapid_key from /api/v2/instance and also updates the key name for server storage, meaning it will invalidate the existing server cache (but this invalidation is still only one-time).
I tested the snapshot version of GoToSocial (0.17.4-SNAPSHOT+git-00bd0f7) with the PR deploy preview (https://deploy-preview-3193--elk-zone.netlify.app/) and the push notification seems to work as expected.
the other is to use the VAPID key in /api/v2/instance for detecting Web Push support, instead of the VAPID key returned when app credentials are created.
Note that although #3193 changed to use /api/v2/instance if available, I didn't change the existing web push support detection logic. (Some other servers doesn't support /api/v2/instance yet so couldn't rely on this solely.)
Hi, we merged #3193 to main branch so you can test the push notification of GoToSocial with the latest Canary version at https://main.elk.zone, which now fetches the vapid key from /api/v2/instance.
We also included the partial 1 week TTL support for appInfo to mitigate the persistent lockout issue.