Do not override user info row on registration endpoint if it already exists

This commit fixes an issue where notification settings would be lost
after restarting Damus, causing unwanted notifications

Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Closes: https://github.com/damus-io/damus/issues/2417
This commit is contained in:
Daniel D’Aquino
2024-09-04 14:25:07 -07:00
parent 11568aa628
commit abb3283eaa
2 changed files with 12 additions and 1 deletions

View File

@ -253,7 +253,7 @@ impl APIHandler {
} }
// Proceed with the main logic after passing all checks // 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 { Ok(APIResponse {
status: StatusCode::OK, status: StatusCode::OK,
body: json!({ "message": "User info saved successfully" }), body: json!({ "message": "User info saved successfully" }),

View File

@ -406,6 +406,17 @@ impl NotificationManager {
} }
// MARK: - User device info and settings // 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<dyn std::error::Error>> {
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( pub async fn save_user_device_info(
&self, &self,