mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 07:19:22 +00:00
Send message when user leave conversation
This commit is contained in:
parent
8a33980a2d
commit
e6906cccc3
@ -4,7 +4,7 @@
|
||||
|
||||
use crate::constants::database_tables_names::{CONV_LIST_TABLE, CONV_MEMBERS_TABLE, CONV_MESSAGES_TABLE};
|
||||
use crate::data::conversation::{Conversation, ConversationMember, ConvID, NewConversationSettings};
|
||||
use crate::data::conversation_message::{ConversationMessage, ConversationMessageFile, ConversationServerMessageType, UserAddedAnotherUserToConversation};
|
||||
use crate::data::conversation_message::{ConversationMessage, ConversationMessageFile, ConversationServerMessageType, UserAddedAnotherUserToConversation, UserRemovedAnotherUserToConversation};
|
||||
use crate::data::error::{ExecError, Res, ResultBoxError};
|
||||
use crate::data::new_conversation::NewConversation;
|
||||
use crate::data::new_conversation_message::NewConversationMessage;
|
||||
@ -65,8 +65,8 @@ pub fn add_member(conv_id: ConvID, user_id: &UserID, following: bool, admin: boo
|
||||
conv_id,
|
||||
ConversationServerMessageType::UserAddedAnotherUserToConversation(UserAddedAnotherUserToConversation {
|
||||
user_who_added: adder.clone(),
|
||||
user_added: user_id.clone()
|
||||
})
|
||||
user_added: user_id.clone(),
|
||||
}),
|
||||
)
|
||||
)?;
|
||||
}
|
||||
@ -448,7 +448,7 @@ pub fn delete_conversation(conv: &Conversation) -> ResultBoxError<()> {
|
||||
}
|
||||
|
||||
/// Delete a conversation membership
|
||||
pub fn remove_member(user_id: &UserID, conv_id: ConvID, _remover: &UserID) -> ResultBoxError<()> {
|
||||
pub fn remove_member(user_id: &UserID, conv_id: ConvID, remover: &UserID) -> ResultBoxError<()> {
|
||||
for msg in get_user_messages_for_conversations(conv_id, user_id)? {
|
||||
delete_message(&msg)?;
|
||||
}
|
||||
@ -459,7 +459,21 @@ pub fn remove_member(user_id: &UserID, conv_id: ConvID, _remover: &UserID) -> Re
|
||||
.cond_user_id("user_id", user_id)
|
||||
.exec()?;
|
||||
|
||||
// TODO : create a message
|
||||
// Create a message
|
||||
if remover == user_id {
|
||||
send_message(&NewConversationMessage::new_server_message(
|
||||
conv_id,
|
||||
ConversationServerMessageType::UserLeftConversation(user_id.clone()),
|
||||
))?;
|
||||
} else {
|
||||
send_message(&NewConversationMessage::new_server_message(
|
||||
conv_id,
|
||||
ConversationServerMessageType::UserRemovedFromConversation(UserRemovedAnotherUserToConversation {
|
||||
user_who_removed: remover.clone(),
|
||||
user_removed: user_id.clone(),
|
||||
}),
|
||||
))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user