From 1351f7163234d798b0e57707fb481aa5f97e939b Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 2 Jul 2023 17:15:01 +0000 Subject: [PATCH] fix(remove_contact_from_chat): do not emit event if the contact was not removed --- src/chat.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index b0eedd158..455d91388 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3180,14 +3180,15 @@ pub async fn remove_contact_from_chat( ); let mut msg = Message::default(); - let mut success = false; let chat = Chat::load_from_db(context, chat_id).await?; if chat.typ == Chattype::Group || chat.typ == Chattype::Broadcast { if !chat.is_self_in_chat(context).await? { - context.emit_event(EventType::ErrorSelfNotInGroup( - "Cannot remove contact from chat; self not in group.".into(), - )); + let err_msg = format!( + "Cannot remove contact {contact_id} from chat {chat_id}: self not in group." + ); + context.emit_event(EventType::ErrorSelfNotInGroup(err_msg.clone())); + bail!("{}", err_msg); } else { // We do not return an error if the contact does not exist in the database. // This allows to delete dangling references to deleted contacts @@ -3219,15 +3220,11 @@ pub async fn remove_contact_from_chat( // in order to correctly determine encryption so if we // removed it first, it would complicate the // check/encryption logic. - success = remove_from_chat_contacts_table(context, chat_id, contact_id) - .await - .is_ok(); + remove_from_chat_contacts_table(context, chat_id, contact_id).await?; context.emit_event(EventType::ChatModified(chat_id)); } - } - - if !success { - bail!("Failed to remove contact"); + } else { + bail!("Cannot remove members from non-group chats."); } Ok(())