mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
refactor: less nested remove_contact_from_chat
This commit is contained in:
29
src/chat.rs
29
src/chat.rs
@@ -4131,17 +4131,21 @@ pub async fn remove_contact_from_chat(
|
||||
delete_broadcast_secret(context, chat_id).await?;
|
||||
}
|
||||
|
||||
if matches!(
|
||||
ensure!(
|
||||
matches!(
|
||||
chat.typ,
|
||||
Chattype::Group | Chattype::OutBroadcast | Chattype::InBroadcast
|
||||
) {
|
||||
if !chat.is_self_in_chat(context).await? {
|
||||
let err_msg = format!(
|
||||
"Cannot remove contact {contact_id} from chat {chat_id}: self not in group."
|
||||
),
|
||||
"Cannot remove members from non-group chats."
|
||||
);
|
||||
|
||||
if !chat.is_self_in_chat(context).await? {
|
||||
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 {
|
||||
}
|
||||
|
||||
let mut sync = Nosync;
|
||||
|
||||
if chat.is_promoted() && chat.typ != Chattype::OutBroadcast {
|
||||
@@ -4158,13 +4162,8 @@ pub async fn remove_contact_from_chat(
|
||||
let addr = contact.get_addr();
|
||||
let fingerprint = contact.fingerprint().map(|f| f.hex());
|
||||
|
||||
let res = send_member_removal_msg(
|
||||
context,
|
||||
&chat,
|
||||
contact_id,
|
||||
addr,
|
||||
fingerprint.as_deref(),
|
||||
)
|
||||
let res =
|
||||
send_member_removal_msg(context, &chat, contact_id, addr, fingerprint.as_deref())
|
||||
.await;
|
||||
|
||||
if contact_id == ContactId::SELF {
|
||||
@@ -4183,10 +4182,6 @@ pub async fn remove_contact_from_chat(
|
||||
if sync.into() {
|
||||
chat.sync_contacts(context).await.log_err(context).ok();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
bail!("Cannot remove members from non-group chats.");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user