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

Push notifications: prevent duplication between remote push notifications and local notifications #1704

Closed
danieldaquino opened this issue Nov 13, 2023 · 6 comments

Comments

@danieldaquino
Copy link
Contributor

For notifications we have two mechanisms:

  • Local notifications: Which locally shows notifications when the app is running on the foreground or the background
    • Local notifications have the advantage of not relying on a central server which is nice in cases when the user does not want to or cannot use our notification relay (e.g. If they only use private relays)
  • Remote push notifications: Shows notifications even when the app is not running.
    • Push notifications have the advantage of always working even when the app is not running.

Ideally we should keep both to enjoy the benefits of each. However, we need to ensure that the user is not getting duplicated notifications.

Acceptance criteria: Implement some mechanism to detect if a notification was already sent either locally or remotely, and ignore duplicate notifications.

@jb55
Copy link
Collaborator

jb55 commented Nov 13, 2023 via email

@danieldaquino
Copy link
Contributor Author

should we add this to the note metadata structure in nostrdb? downside is we won't have ndb in remote notifications v1 :(

That would be a nice way of doing it, when we have ndb support on the extension.

If we need to implement this ticket before adding ndb support, perhaps using UserDefaults might work as well. Given the transient nature of notifications, I imagine we don't even need to keep this type of info longer than 1 week or so.

We can probably make the whole system suppress notifications of events older than 1 week, so that we can model it as a temporary cache more than a permanent DB, and thus eliminate certain complexities like DB migrations and so on.

@danieldaquino danieldaquino self-assigned this Nov 21, 2023
danieldaquino added a commit that referenced this issue Nov 23, 2023
This commit adds a new cache that serves as a coordinator between local and remote/push notifications to avoid showing two notifications for the same event to the user.

Testing
-------

Device: iPhone 15 Pro simulator
iOS: 17.0.1
Damus: This commit
Coverage:
1. New unit tests are passing
2. Triggered a local notification with the app open, and then sent a remote push notification for the same event. Local notification shown and remote push notification suppressed. PASS
3. Triggered a push notification for an event that was not yet in the cache. Push notification is displayed as expected. PASS
4. Triggered a new push notification while the app was turned off. Remote push notification is displayed first, and local notification for the same event is suppressed. PASS

Changelog-Added: Prevent duplicate notifications for the same events
Closes: #1704
@danieldaquino
Copy link
Contributor Author

Sent a patch via email! 🤙

All testing, code, and notes can be visualized here:
https://groups.google.com/a/damus.io/g/patches/c/ra36yY_oCis

@alltheseas
Copy link
Collaborator

Need to add switch local <-> push notifications

@danieldaquino
Copy link
Contributor Author

A relevant note from an old patch email conversation to further elaborate the switch between local <-> push notifications mentioned above:

I think we should not worry about the de-duplication and have a way to switch between local and remote notifications.

@danieldaquino
Copy link
Contributor Author

Sent patches!

@jb55 please let me know if you have any questions or concerns, thank you!

danieldaquino added a commit that referenced this issue May 24, 2024
Changing the notification mode setting requires successfully sending or
revoking the device token to the server. As this is an action that might
fail, it is important to have a clear UX feedback in case this fails.

Testing
--------

PASS

Device: iPhone 15 simulator
iOS: 17.4
Damus: This commit
strfry-push-notify: d6c2ff289c80e0a90874a7499ed6408394659fc9
Coverage:
1. Checked that push notification mode setting is invisible when experimental push notifications mode is disabled
2. Checked that push notification mode setting is visible when experimental push notifications mode is enabled
3. Checked that switching between push and local notifications sends requests to the server
4. Checked that switching to push notification mode will cause local notifications to be suppressed and push notifications will be sent to the APNS server
5. Checked that switching back to local notification mode will cause local notifications to be displayed, and push notifications will NOT be sent to APNS
6. Checked that if the API server is off, switching from local to push notification modes is not possible and shows an error to the user.
7. Checked that sending APNS payload to Apple's test APNS page will actually deliver the push notification successfully.

Closes: #1704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Review
Development

No branches or pull requests

3 participants