1
0
mirror of https://gitlab.com/comunic/comunicapiv3 synced 2024-11-26 07:19:22 +00:00

Unregister user when removing him

This commit is contained in:
Pierre HUBERT 2021-03-07 19:30:02 +01:00
parent 7ae8fb2fad
commit 0f4b7af449
5 changed files with 52 additions and 1 deletions

View File

@ -65,4 +65,5 @@ pub mod left_call_message;
pub mod new_call_signal;
pub mod call_peer_ready;
pub mod call_peer_interrupted_streaming;
pub mod res_check_password_token;
pub mod res_check_password_token;
pub mod remove_user_from_conv_message;

View File

@ -0,0 +1,23 @@
//! # Removed user from conversation message
//!
//! @author Pierre Hubert
use serde::Serialize;
use crate::data::conversation::ConvID;
use crate::data::user::UserID;
#[derive(Serialize)]
pub struct RemovedUserFromConversationMessage {
user_id: u64,
conv_id: u64,
}
impl RemovedUserFromConversationMessage {
pub fn new(user_id: &UserID, conv_id: ConvID) -> Self {
Self {
user_id: user_id.id(),
conv_id: conv_id.id(),
}
}
}

View File

@ -7,6 +7,7 @@ use std::collections::HashSet;
use crate::api_data::conversation_api::ConversationAPI;
use crate::api_data::conversation_message_api::ConversationMessageAPI;
use crate::api_data::list_unread_conversations_api::UnreadConversationAPI;
use crate::api_data::remove_user_from_conv_message::RemovedUserFromConversationMessage;
use crate::api_data::res_count_unread_conversations::ResultCountUnreadConversations;
use crate::api_data::res_create_conversation::ResCreateConversation;
use crate::api_data::res_find_private_conversations::ResFindPrivateConversations;
@ -508,6 +509,26 @@ pub fn handle_event(e: &events_helper::Event) -> Res {
)?;
}
Event::RemovedUserFromConversation(user_id, conv_id) => {
// Notify users
user_ws_controller::send_message_to_specific_connections(
|f| f.conversations.contains(conv_id),
|_| UserWsMessage::no_id_message("removed_user_from_conv", RemovedUserFromConversationMessage::new(user_id, *conv_id)),
None::<fn(&_) -> _>,
)?;
// Disconnected users
user_ws_controller::foreach_connection(|f| {
if f.user_id() == user_id && f.conversations.contains(conv_id) {
f.clone().replace(|w| {
w.conversations.remove(conv_id);
});
}
Ok(())
})?;
}
_ => {}
}

View File

@ -488,6 +488,9 @@ pub fn remove_member(user_id: &UserID, conv_id: ConvID, remover: &UserID) -> Res
))?;
}
// Propagate event
events_helper::propagate_event(&Event::RemovedUserFromConversation(user_id, conv_id))?;
Ok(())
}

View File

@ -38,6 +38,9 @@ pub enum Event<'a> {
/// Deleted a conversation message
DeleteConversationMessage(&'a ConversationMessage),
/// Removed a user from a conversation
RemovedUserFromConversation(&'a UserID, ConvID),
/// Created a new comment
NewComment(&'a Comment),