1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-22 21:39:21 +00:00

Propagate an event when deleting a conversation

This commit is contained in:
Pierre HUBERT 2021-03-13 12:22:35 +01:00
parent 4776207ce8
commit 0d8a514392
3 changed files with 26 additions and 0 deletions

View File

@ -544,6 +544,26 @@ pub fn handle_event(e: &events_helper::Event) -> Res {
})?; })?;
} }
Event::DeletedConversation(conv_id) => {
// Notify users
user_ws_controller::send_message_to_specific_connections(
|f| f.conversations.contains(conv_id),
|_| UserWsMessage::no_id_message("deleted_conversation", conv_id.id()),
None::<fn(&_) -> _>,
)?;
// Disconnect user from conversation
user_ws_controller::foreach_connection(|f| {
if f.conversations.contains(conv_id) {
f.clone().replace(|w| {
w.conversations.remove(conv_id);
});
}
Ok(())
})?;
}
_ => {} _ => {}
} }

View File

@ -453,6 +453,9 @@ pub fn delete_conversation(conv: &Conversation) -> ResultBoxError<()> {
.cond_conv_id("id", conv.id) .cond_conv_id("id", conv.id)
.exec()?; .exec()?;
// Propagate information
events_helper::propagate_event(&Event::DeletedConversation(conv.id))?;
Ok(()) Ok(())
} }

View File

@ -44,6 +44,9 @@ pub enum Event<'a> {
/// Removed a user from a conversation /// Removed a user from a conversation
RemovedUserFromConversation(&'a UserID, ConvID), RemovedUserFromConversation(&'a UserID, ConvID),
/// Delete a conversation
DeletedConversation(ConvID),
/// Created a new comment /// Created a new comment
NewComment(&'a Comment), NewComment(&'a Comment),