mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
fix: Clear draft when leaving a group or when Self is removed.
Fix #6175. This is not a very bad bug (even WhatsApp has the same bug, and WhatsApp rarely has any bugs at all!), so I think it's fine not to add regression tests. I did test that it works on an Android phone. Clearing the draft when a different device leaves the group or when Self is removed from the group works. What doesn't work is clearing the draft when leaving a group from this device, because after leaving, the UI still has the draft in the now-hidden input bar, and calls set_draft() when the user leaves the activity, re-adding the draft. We could fix this by loading the chat in do_set_draft(), calling, `is_self_in_chat()`, and not setting the draft if self isn't in the chat. This is two extra database calls everytime the user leaves a group and goes back to the chat list - not a big deal, but I'm nonetheless not sure it's worth it for this super arcane bug. What do you think?
This commit is contained in:
10
src/chat.rs
10
src/chat.rs
@@ -3921,6 +3921,11 @@ pub async fn remove_contact_from_chat(
|
|||||||
let mut msg = Message::default();
|
let mut msg = Message::default();
|
||||||
|
|
||||||
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 && contact_id == ContactId::SELF {
|
||||||
|
chat_id.set_draft(context, None).await?; // Clear draft since the user left the group.
|
||||||
|
}
|
||||||
|
|
||||||
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? {
|
||||||
let err_msg = format!(
|
let err_msg = format!(
|
||||||
@@ -4611,6 +4616,11 @@ async fn set_contacts_by_addrs(context: &Context, id: ChatId, addrs: &[String])
|
|||||||
if contacts == contacts_old {
|
if contacts == contacts_old {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if chat.typ == Chattype::Group && !contacts.contains(&ContactId::SELF) {
|
||||||
|
id.set_draft(context, None).await?; // Clear draft since the user left the group.
|
||||||
|
}
|
||||||
|
|
||||||
update_chat_contacts_table(context, id, &contacts).await?;
|
update_chat_contacts_table(context, id, &contacts).await?;
|
||||||
context.emit_event(EventType::ChatModified(id));
|
context.emit_event(EventType::ChatModified(id));
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -2317,6 +2317,9 @@ async fn apply_group_changes(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if new_members != chat_contacts {
|
if new_members != chat_contacts {
|
||||||
|
if !new_members.contains(&ContactId::SELF) {
|
||||||
|
chat_id.set_draft(context, None).await?; // Clear draft since Self was removed from the group.
|
||||||
|
}
|
||||||
chat::update_chat_contacts_table(context, chat_id, &new_members).await?;
|
chat::update_chat_contacts_table(context, chat_id, &new_members).await?;
|
||||||
chat_contacts = new_members;
|
chat_contacts = new_members;
|
||||||
send_event_chat_modified = true;
|
send_event_chat_modified = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user