From f9885b01aa7a367e086b5c90668ef3a924ec07a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Fri, 6 Sep 2024 18:32:20 -0700 Subject: [PATCH] Fix issue with multiple device tokens MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Testing ------- Device: iPhone 15 simulator iOS: 17.5 Damus: 1.10 (8) 3902fe7b30f38ec104c13087948799e38e26fa91 (Local build) notepush: This commit Setup: 1. Open app in two separate simulator devices under the same nostr account 2. On both, setup the environment to be local, pointing to the same local notepush Steps: 1. Go to notification settings and try to set notification mode to "push" on both devices 2. Ensure both can be set to push without displaying an error 3. Ensure preferences can be changed without displaying an error 4. When changing one setting, on both devices go back and forth on the notification setting screen and ensure both are independent 5. Send some notifications to this account. Ensure both get the notification 6. Disable DM notifications on one device and send a DM. Ensure only one device gets the notification 7. Try step 6 again, but with likes (and disabling it on the other device) Results: PASS - Can register with both devices - Both devices get new push notifications - Settings are independent and get respected on each device. Signed-off-by: Daniel D’Aquino Closes: https://github.com/damus-io/damus/issues/2434 --- src/notification_manager/notification_manager.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/notification_manager/notification_manager.rs b/src/notification_manager/notification_manager.rs index b42b806..a19b08e 100644 --- a/src/notification_manager/notification_manager.rs +++ b/src/notification_manager/notification_manager.rs @@ -307,6 +307,15 @@ impl NotificationManager { } } + async fn is_pubkey_token_pair_registered( + &self, + pubkey: &PublicKey, + device_token: &str, + ) -> Result> { + let current_device_tokens = self.get_user_device_tokens(pubkey).await?; + Ok(current_device_tokens.contains(&device_token.to_string())) + } + async fn is_pubkey_registered( &self, pubkey: &PublicKey, @@ -421,7 +430,7 @@ impl NotificationManager { pubkey: nostr::PublicKey, device_token: &str, ) -> Result<(), Box> { - if self.is_pubkey_registered(&pubkey).await? { + if self.is_pubkey_token_pair_registered(&pubkey, &device_token).await? { return Ok(()); } self.save_user_device_info(pubkey, device_token).await