diff --git a/apps/backend/src/miscellaneous/resolver.rs b/apps/backend/src/miscellaneous/resolver.rs index e8a8f6e584..7e52262914 100644 --- a/apps/backend/src/miscellaneous/resolver.rs +++ b/apps/backend/src/miscellaneous/resolver.rs @@ -976,7 +976,12 @@ impl MiscellaneousMutation { async fn test_user_notification_platforms(&self, gql_ctx: &Context<'_>) -> Result { let service = gql_ctx.data_unchecked::>(); let user_id = service.user_id_from_ctx(gql_ctx).await?; - service.test_user_notification_platforms(user_id).await + service + .send_notifications_to_user_platforms( + user_id, + format!("Test notification message triggered."), + ) + .await } /// Delete a notification platform for the currently logged in user. @@ -3520,16 +3525,6 @@ impl MiscellaneousService { Ok(new_notification_id) } - async fn test_user_notification_platforms(&self, user_id: i32) -> Result { - let user = self.user_by_id(user_id).await?; - self.send_notifications_to_user_platforms( - user_id, - format!("Test notification message triggered."), - ) - .await?; - Ok(true) - } - async fn delete_user_notification_platform( &self, user_id: i32, @@ -3952,10 +3947,15 @@ impl MiscellaneousService { &self, user_id: i32, msg: String, - ) -> Result<()> { + ) -> Result { let user = self.user_by_id(user_id).await?; - for notification in user.notifications.0 {} - Ok(()) + let mut success = true; + for notification in user.notifications.0 { + if notification.settings.send_message(&msg).await.is_err() { + success = false; + } + } + Ok(success) } } diff --git a/apps/backend/src/notification.rs b/apps/backend/src/notification.rs index 5d516e9ba0..49dac924bf 100644 --- a/apps/backend/src/notification.rs +++ b/apps/backend/src/notification.rs @@ -8,7 +8,7 @@ use crate::{ impl UserNotificationSetting { // TODO: Allow formatting messages - pub async fn send_message(&self, msg: String) -> Result<()> { + pub async fn send_message(&self, msg: &str) -> Result<()> { let project_name = PROJECT_NAME.to_case(Case::Title); match self { Self::Discord { url } => { @@ -61,7 +61,7 @@ impl UserNotificationSetting { .map(|p| p.to_string()) .unwrap_or_else(|| "3".to_owned()), ) - .body_string(msg) + .body_string(msg.to_owned()) .await .map_err(|e| anyhow!(e))?; }