Not a bug Push Notifications: Please consider that a subscription might already exist (with no or different VAPID key)

Steffen

Well-known member
Affected version
2.1 Beta 5
It's great that XenForo 2.1 will support web push notifications! We have already been using them (completely decoupled from our forum) for notifying users about new articles on our website (https://www.computerbase.de/push/). This implementation is a few years old (it doesn't even use VAPID and the subscriptions are not associated with user accounts). But still, PushManager.getSubscription returns a valid subscription.

I've been wondering what happens with these subscriptions when we upgrade to XenForo 2.1 (and enable XenForo's push notifications). From looking at the code in core.js, it seems like XenForo would treat such an already existing subscription like one of its own subscriptions and either unsubscribe them (if the user is logged-out) or create/update an entry in "xf_user_push_subscription" (if the user is logged-in). The former is okay (although not very kind ;)). The latter definitely seems problematic because XenForo doesn't know the VAPID key that was used to create the subscription (if any), so this entry seems useless and I'm pretty sure it cannot work.

I think that when XenForo looks for an already existing subscription (in the JavaScript function getSubscription) it should check whether the subscription's applicationServerKey matches XF.config.pushAppServerKey. If it does then proceed as currently implemented. What should happen if it doesn't match is more difficult. It doesn't seem to be possible to have multiple co-existing push subscriptions per domain / service-worker. I think XenForo should ignore such subscriptions (leave them be) until the user explicitly enables push notifications in XenForo.

If/when the user enables XenForo's own push notifications then I think there is nothing else that XenForo can do than unsubscribing the old subscription and creating a new subscription (and thereby disabling the push subscriptions of the other software running on the same domain). But could you then please trigger some kind of event like push:init-upgraded (and pass the old subscription as a parameter)? This should make it possible for me to essentially move the article subscriptions from our legacy push service over to XenForo.
 
Last edited:
Hmm, it seems like it's possible to have multiple service workers per domain if they use different scopes. Maybe this is a non-issue because XenForo's service worker already has an implicit scope of "/community/js/xf/". I'll have to try that.
 
Last edited:
Top Bottom