Skip to content

Commit

Permalink
fix(backend): notifications not being trigerred
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Jul 30, 2023
1 parent 83da069 commit a78d67c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
28 changes: 14 additions & 14 deletions apps/backend/src/miscellaneous/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,12 @@ impl MiscellaneousMutation {
async fn test_user_notification_platforms(&self, gql_ctx: &Context<'_>) -> Result<bool> {
let service = gql_ctx.data_unchecked::<Arc<MiscellaneousService>>();
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.
Expand Down Expand Up @@ -3520,16 +3525,6 @@ impl MiscellaneousService {
Ok(new_notification_id)
}

async fn test_user_notification_platforms(&self, user_id: i32) -> Result<bool> {
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,
Expand Down Expand Up @@ -3952,10 +3947,15 @@ impl MiscellaneousService {
&self,
user_id: i32,
msg: String,
) -> Result<()> {
) -> Result<bool> {
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)
}
}

Expand Down
4 changes: 2 additions & 2 deletions apps/backend/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 } => {
Expand Down Expand Up @@ -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))?;
}
Expand Down

0 comments on commit a78d67c

Please sign in to comment.