diff --git a/src/data/conversation_message.rs b/src/data/conversation_message.rs index be469fb..716d062 100644 --- a/src/data/conversation_message.rs +++ b/src/data/conversation_message.rs @@ -4,13 +4,13 @@ use std::collections::HashSet; +use crate::data::conversation::ConvID; use crate::data::error::{ExecError, Res}; use crate::data::user::UserID; -use crate::data::conversation::ConvID; pub type ConvMessageID = u64; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct ConversationMessageFile { pub path: String, pub size: u64, @@ -19,19 +19,19 @@ pub struct ConversationMessageFile { pub r#type: String, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct UserAddedAnotherUserToConversation { pub user_who_added: UserID, pub user_added: UserID, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct UserRemovedAnotherUserToConversation { pub user_who_removed: UserID, pub user_removed: UserID, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub enum ConversationServerMessageType { UserCreatedConversation(UserID), UserAddedAnotherUserToConversation(UserAddedAnotherUserToConversation), @@ -98,7 +98,7 @@ impl ConversationServerMessageType { } /// Information about a single conversation message -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct ConversationMessage { pub id: ConvMessageID, pub time_sent: u64, diff --git a/src/helpers/push_notifications_helper.rs b/src/helpers/push_notifications_helper.rs index 5264c50..733e547 100644 --- a/src/helpers/push_notifications_helper.rs +++ b/src/helpers/push_notifications_helper.rs @@ -169,21 +169,26 @@ pub fn cancel_conversation_notification(conv_id: ConvID, users: Option Res { - if let Err(e) = handle_event_internal(e) { - eprintln!("Failed to create push notifications associated with event! {}", e); - } - - Ok(()) -} - -fn handle_event_internal(e: &Event) -> Res { match e { Event::NewConversationMessage(msg) => { - create_conversation_notification(msg)?; + let msg = (*msg).clone(); + std::thread::spawn(move || { + if let Err(err) = create_conversation_notification(&msg) { + eprintln!("Failed to create push for conversation! {}", err); + } + }); } + Event::SeenLastConversationMessage(user_id, conv_id) => { - cancel_conversation_notification(*conv_id, Some(vec![user_id.as_owned()]))?; + let user_id = user_id.as_owned(); + let conv_id = *conv_id; + std::thread::spawn(move || { + if let Err(e) = cancel_conversation_notification(conv_id, Some(vec![user_id])) { + eprintln!("Failed to cancel push conversation! {}", e); + } + }); } + _ => {} }