Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: iOS PWA push notifications #1794

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

Soxasora
Copy link
Member

@Soxasora Soxasora commented Jan 4, 2025

Description

At last, the final fix of #756

1: Push notifications continue to be lost #411

This has been a lesson in patience with iOS, I must say. And also I got it really wrong with my previous fix!

Some key takeaways

  1. onPush event must result in a notification being shown1
  2. The notification must be shown in a timely manner in respect to the event2
  3. onPush thus can't be asynchronous by itself but needs something like event.waitUntil

To be able to use functions like getNotifications, setAppBadge, etc. we need to group them into an array of Promises that once resolved, will trigger showNotification; all encapsulated in event.waitUntil that will, indeed, wait for them to be resolved.1

If we don't respect those 3 keys, an async function like getNotifications will cause showNotification to happen outside of onPush event and will result in user's subscription being revoked.2

tl;dr A lot of text to say that we were sending the notification out of the event because of await getNotifications


2: Notification counts are wacky

The previous fix (#1796) enabled @ekzyis's iOS check to force counts to start from 1, it helped us provide immediate relief to iOS users that received mention counts all over the place

By meddling around the merging code, I discovered that now we don't need iOS-specific code to achieve proper counting, we already do that by injecting amount and sats into the notification payload and get it back for us to use it on the next merge.

About amount, we're gonna use it just for showing the correct count. We'll get the length of the notifications array to get how many notifications of the same tag are still open and do +1 (much like we were already doing)


3: when I click on notification replies I get sent to really old threads

The previous fix (#1801) included the url inside the merged notification, now the url is '/notifications' as previously intended but wasn't working


4: sat stacking notifications aren't replaced

While we can't replace them on iOS, values are finally correct!

Screenshots

TODO

Additional Context

It contains commented-out logger and getOS that even if unused, might be particularly useful during debugging

Checklist

Are your changes backwards compatible? Please answer below:
It doesn't mess with already present keys! I can say this is a backwards compatible solution.

On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
8, from all the earlier PRs to now, I'm pretty confident about push sub retention.
I didn't test all the notifications but they follow the same behavior as before + counting/sumsat fixes

For frontend changes: Tested on mobile, light and dark mode? Please answer below:
n/a

Did you introduce any new environment variables? If so, call them out explicitly here:
No

Footnotes

  1. When requesting a push subscription you must promise that all pushes will be user visible events. This means that each push event you process must result in a user visible notification being displayed with a call to self.registration.showNotification(), src: Badging for Home Screen Web Apps 2

  2. After three push events where you fail to post a notification in a timely manner, your site's push subscription will be revoked. 2

@Soxasora Soxasora added the bug label Jan 4, 2025
@Soxasora Soxasora changed the title fix: iOS PWA push notifications track: iOS PWA push notifications Jan 5, 2025
@Soxasora Soxasora added feature new product features that weren't there before and removed feature new product features that weren't there before labels Jan 5, 2025
@Soxasora Soxasora changed the title track: iOS PWA push notifications fix: iOS PWA push notifications Jan 6, 2025
@Soxasora Soxasora force-pushed the ios_pwa_push_notifications branch from 21487fa to 261c377 Compare January 6, 2025 17:36
@Soxasora Soxasora force-pushed the ios_pwa_push_notifications branch from 11c0157 to 799412f Compare January 6, 2025 19:41
@Soxasora Soxasora force-pushed the ios_pwa_push_notifications branch from 799412f to f51869a Compare January 6, 2025 19:43
@Soxasora Soxasora marked this pull request as ready for review January 6, 2025 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant