damus icon indicating copy to clipboard operation
damus copied to clipboard

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

Open danieldaquino opened this issue 2 years ago • 5 comments

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.

danieldaquino avatar Nov 13 '23 18:11 danieldaquino

On Mon, Nov 13, 2023 at 10:27:56AM -0800, Daniel D’Aquino wrote:

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.

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

jb55 avatar Nov 13 '23 19:11 jb55

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 avatar Nov 15 '23 17:11 danieldaquino

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

danieldaquino avatar Nov 23 '23 08:11 danieldaquino

Need to add switch local <-> push notifications

alltheseas avatar Feb 05 '24 17:02 alltheseas

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 avatar May 03 '24 17:05 danieldaquino

Sent patches!

  • Client-side: https://groups.google.com/a/damus.io/g/patches/c/xJJGs2-a6f0
  • Server-side: https://groups.google.com/a/damus.io/g/patches/c/9roECAoeZBk

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

danieldaquino avatar May 21 '24 04:05 danieldaquino