fix(remove_contact_from_chat): do not emit event if the contact was not removed

This commit is contained in:
link2xt
2023-07-02 17:15:01 +00:00
parent d42322b38b
commit 1351f71632

View File

@@ -3180,14 +3180,15 @@ pub async fn remove_contact_from_chat(
); );
let mut msg = Message::default(); let mut msg = Message::default();
let mut success = false;
let chat = Chat::load_from_db(context, chat_id).await?; let chat = Chat::load_from_db(context, chat_id).await?;
if chat.typ == Chattype::Group || chat.typ == Chattype::Broadcast { if chat.typ == Chattype::Group || chat.typ == Chattype::Broadcast {
if !chat.is_self_in_chat(context).await? { if !chat.is_self_in_chat(context).await? {
context.emit_event(EventType::ErrorSelfNotInGroup( let err_msg = format!(
"Cannot remove contact from chat; self not in group.".into(), "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 { } else {
// We do not return an error if the contact does not exist in the database. // We do not return an error if the contact does not exist in the database.
// This allows to delete dangling references to deleted contacts // 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 // in order to correctly determine encryption so if we
// removed it first, it would complicate the // removed it first, it would complicate the
// check/encryption logic. // check/encryption logic.
success = remove_from_chat_contacts_table(context, chat_id, contact_id) remove_from_chat_contacts_table(context, chat_id, contact_id).await?;
.await
.is_ok();
context.emit_event(EventType::ChatModified(chat_id)); context.emit_event(EventType::ChatModified(chat_id));
} }
} } else {
bail!("Cannot remove members from non-group chats.");
if !success {
bail!("Failed to remove contact");
} }
Ok(()) Ok(())