Skip to content

Fix push notifications randomly getting deactivated

Jano requested to merge webpush_issues_1 into master

Fixes point 5 of #831 (closed)

What does this MR do?

@fs_k and me discovered that if you subscribe to push notifications, after a while you won't receive them any more and the settings will tell you that you are not subscribed to them any more. You then need to resubscribe to receive them again.

Seems like browsers sometimes decide to reset their push subscription data and therefore invalidate all of their push subscriptions. You need to keep track on the pushsubscriptionchange event to resubscribe to push notifications when that happens. The old subscription will remain on the server, but only until the next time the server tries to send a notification to that endpoint; then the server will realize that the endpoint is dead and remove the old subscription.

How confident are you it won't break things if deployed?

Pretty much very. Tested that it doesn't break subscribing and receiving push notifications.

How to test

This thing seems to kind of not at all be testable.

According to https://stackoverflow.com/questions/36602136/how-can-i-test-pushsubscriptionchange-event-handling-code you can only do a functional test by firing up the event manally, but in the end this will only test the following three lines of code:

self.addEventListener('pushsubscriptionchange', function (event) {
  event.waitUntil(subscribeForPushNotifications(event.oldSubscription.options))
})

Let's just deploy it and see if it works. At least it seems to not break anything.

Screenshots (if applicable)

Not applicable.

Checklist

  • added a test, or explain why one is not needed/possible...
  • no unrelated changes
  • asked someone for a code review
  • joined #foodsharing-beta channel at https://slackin.yunity.org
  • added an entry to CHANGELOG.md (description, merge request link, username(s)) // belongs to Add Web Push Notifications IMHO
  • Once your MR has been merged, you are responsible to update the #foodsharing-beta Slack channel about what has been changed here. They will test your work in different browsers, roles or other settings
Edited by Alex

Merge request reports