-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Jan 4, 2025
Soxasora
changed the title
fix: iOS PWA push notifications
track: iOS PWA push notifications
Jan 5, 2025
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
changed the title
track: iOS PWA push notifications
fix: iOS PWA push notifications
Jan 6, 2025
Soxasora
force-pushed
the
ios_pwa_push_notifications
branch
from
January 6, 2025 17:36
21487fa
to
261c377
Compare
Soxasora
force-pushed
the
ios_pwa_push_notifications
branch
from
January 6, 2025 19:41
11c0157
to
799412f
Compare
Soxasora
force-pushed
the
ios_pwa_push_notifications
branch
from
January 6, 2025 19:43
799412f
to
f51869a
Compare
Soxasora
force-pushed
the
ios_pwa_push_notifications
branch
from
January 7, 2025 16:53
06e12b7
to
d5d4ce8
Compare
Soxasora
force-pushed
the
ios_pwa_push_notifications
branch
from
January 7, 2025 20:01
d5d4ce8
to
7015a57
Compare
This is awesome. I'm so tired of this bug. I'll QA a little now and merge it soon after. |
I loved this adventure, thank you! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
onPush
event must result in a notification being shown1onPush
thus can't be asynchronous by itself but needs something likeevent.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 triggershowNotification
; all encapsulated inevent.waitUntil
that will, indeed, wait for them to be resolved.1If we don't respect those 3 keys, an async function like
getNotifications
will causeshowNotification
to happen outside ofonPush
event and will result in user's subscription being revoked.2tl;dr A lot of text to say that we were losing the subscription because we used to send the notification out of the event with
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
andsats
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)Another problem was the missing support for notification filtering by tag, can confirm that iOS supports it.
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
onPush doesn't have the ability to access the default logger without bloating it, I used the (commented-out) logger from #1797 and added a comment that remembers us to use an HTTPS endpoint on the logger otherwise we can't access it
Didn't remove getOS that, even if unused, might be particularly useful during debugging
An observation:
There's a ultra-rare possibility that a push subscription could be revoked if we ever mess with sending notifications without a payload as the
onPush
event really requires a notification to be shown regardless and we drop the notification if the payload is not thereStill, we're protected by
onPushSubscriptionChange
->RESUBSCRIBE
in case this happens!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
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
After three push events where you fail to post a notification in a timely manner, your site's push subscription will be revoked. ↩ ↩2