mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2025-06-20 16:35:17 +00:00
Spawn a thread to send push notifications
This commit is contained in:
@ -169,21 +169,26 @@ pub fn cancel_conversation_notification(conv_id: ConvID, users: Option<Vec<UserI
|
||||
|
||||
/// Handle event. This method NEVER returns Err
|
||||
pub fn handle_event(e: &Event) -> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user