mirror of
https://github.com/chatmail/core.git
synced 2026-04-29 11:26: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?;
|
delete_broadcast_secret(context, chat_id).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches!(
|
ensure!(
|
||||||
|
matches!(
|
||||||
chat.typ,
|
chat.typ,
|
||||||
Chattype::Group | Chattype::OutBroadcast | Chattype::InBroadcast
|
Chattype::Group | Chattype::OutBroadcast | Chattype::InBroadcast
|
||||||
) {
|
),
|
||||||
if !chat.is_self_in_chat(context).await? {
|
"Cannot remove members from non-group chats."
|
||||||
let err_msg = format!(
|
|
||||||
"Cannot remove contact {contact_id} from chat {chat_id}: self not in group."
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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()));
|
context.emit_event(EventType::ErrorSelfNotInGroup(err_msg.clone()));
|
||||||
bail!("{err_msg}");
|
bail!("{err_msg}");
|
||||||
} else {
|
}
|
||||||
|
|
||||||
let mut sync = Nosync;
|
let mut sync = Nosync;
|
||||||
|
|
||||||
if chat.is_promoted() && chat.typ != Chattype::OutBroadcast {
|
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 addr = contact.get_addr();
|
||||||
let fingerprint = contact.fingerprint().map(|f| f.hex());
|
let fingerprint = contact.fingerprint().map(|f| f.hex());
|
||||||
|
|
||||||
let res = send_member_removal_msg(
|
let res =
|
||||||
context,
|
send_member_removal_msg(context, &chat, contact_id, addr, fingerprint.as_deref())
|
||||||
&chat,
|
|
||||||
contact_id,
|
|
||||||
addr,
|
|
||||||
fingerprint.as_deref(),
|
|
||||||
)
|
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
if contact_id == ContactId::SELF {
|
if contact_id == ContactId::SELF {
|
||||||
@@ -4183,10 +4182,6 @@ pub async fn remove_contact_from_chat(
|
|||||||
if sync.into() {
|
if sync.into() {
|
||||||
chat.sync_contacts(context).await.log_err(context).ok();
|
chat.sync_contacts(context).await.log_err(context).ok();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
bail!("Cannot remove members from non-group chats.");
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user