From abb3283eaa270c0f5a66488084e2833ab2e9a145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Wed, 4 Sep 2024 14:25:07 -0700 Subject: [PATCH] Do not override user info row on registration endpoint if it already exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes an issue where notification settings would be lost after restarting Damus, causing unwanted notifications Signed-off-by: Daniel D’Aquino Closes: https://github.com/damus-io/damus/issues/2417 --- src/api_request_handler.rs | 2 +- src/notification_manager/notification_manager.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/api_request_handler.rs b/src/api_request_handler.rs index b55f646..95c567a 100644 --- a/src/api_request_handler.rs +++ b/src/api_request_handler.rs @@ -253,7 +253,7 @@ impl APIHandler { } // Proceed with the main logic after passing all checks - self.notification_manager.save_user_device_info(pubkey, device_token).await?; + self.notification_manager.save_user_device_info_if_not_present(pubkey, device_token).await?; Ok(APIResponse { status: StatusCode::OK, body: json!({ "message": "User info saved successfully" }), diff --git a/src/notification_manager/notification_manager.rs b/src/notification_manager/notification_manager.rs index 11ffe56..ab3d01b 100644 --- a/src/notification_manager/notification_manager.rs +++ b/src/notification_manager/notification_manager.rs @@ -406,6 +406,17 @@ impl NotificationManager { } // MARK: - User device info and settings + + pub async fn save_user_device_info_if_not_present( + &self, + pubkey: nostr::PublicKey, + device_token: &str, + ) -> Result<(), Box> { + if self.is_pubkey_registered(&pubkey).await? { + return Ok(()); + } + self.save_user_device_info(pubkey, device_token).await + } pub async fn save_user_device_info( &self,