fix(remove_contact_from_chat): bubble up chat loading errors

This commit is contained in:
link2xt
2023-07-02 17:13:58 +00:00
parent ce6876c418
commit d42322b38b

View File

@@ -3182,7 +3182,7 @@ pub async fn remove_contact_from_chat(
let mut msg = Message::default(); let mut msg = Message::default();
let mut success = false; let mut success = false;
if let Ok(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( context.emit_event(EventType::ErrorSelfNotInGroup(
@@ -3197,15 +3197,10 @@ pub async fn remove_contact_from_chat(
msg.viewtype = Viewtype::Text; msg.viewtype = Viewtype::Text;
if contact.id == ContactId::SELF { if contact.id == ContactId::SELF {
set_group_explicitly_left(context, &chat.grpid).await?; set_group_explicitly_left(context, &chat.grpid).await?;
msg.text = msg.text = Some(stock_str::msg_group_left(context, ContactId::SELF).await);
Some(stock_str::msg_group_left(context, ContactId::SELF).await);
} else { } else {
msg.text = Some( msg.text = Some(
stock_str::msg_del_member( stock_str::msg_del_member(context, contact.get_addr(), ContactId::SELF)
context,
contact.get_addr(),
ContactId::SELF,
)
.await, .await,
); );
} }
@@ -3230,7 +3225,6 @@ pub async fn remove_contact_from_chat(
context.emit_event(EventType::ChatModified(chat_id)); context.emit_event(EventType::ChatModified(chat_id));
} }
} }
}
if !success { if !success {
bail!("Failed to remove contact"); bail!("Failed to remove contact");