diff --git a/deltachat-repl/src/cmdline.rs b/deltachat-repl/src/cmdline.rs index d48ad4b58..b7753f994 100644 --- a/deltachat-repl/src/cmdline.rs +++ b/deltachat-repl/src/cmdline.rs @@ -70,11 +70,6 @@ async fn reset_tables(context: &Context, bits: i32) { .await .unwrap(); context.sql().config_cache().write().await.clear(); - context - .sql() - .execute("DELETE FROM leftgrps;", ()) - .await - .unwrap(); println!("(8) Rest but server config reset."); } diff --git a/src/chat.rs b/src/chat.rs index 0526eed3d..f375c7028 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3881,7 +3881,6 @@ pub async fn remove_contact_from_chat( if contact_id == ContactId::SELF { res?; - set_group_explicitly_left(context, &chat.grpid).await?; } else if let Err(e) = res { warn!( context, @@ -3935,25 +3934,6 @@ async fn send_member_removal_msg( send_msg(context, chat.id, &mut msg).await } -async fn set_group_explicitly_left(context: &Context, grpid: &str) -> Result<()> { - if !is_group_explicitly_left(context, grpid).await? { - context - .sql - .execute("INSERT INTO leftgrps (grpid) VALUES(?);", (grpid,)) - .await?; - } - - Ok(()) -} - -pub(crate) async fn is_group_explicitly_left(context: &Context, grpid: &str) -> Result { - let exists = context - .sql - .exists("SELECT COUNT(*) FROM leftgrps WHERE grpid=?;", (grpid,)) - .await?; - Ok(exists) -} - /// Sets group or mailing list chat name. pub async fn set_chat_name(context: &Context, chat_id: ChatId, new_name: &str) -> Result<()> { rename_ex(context, Sync, chat_id, new_name).await diff --git a/src/chat/chat_tests.rs b/src/chat/chat_tests.rs index 45c228834..e01718b55 100644 --- a/src/chat/chat_tests.rs +++ b/src/chat/chat_tests.rs @@ -4867,3 +4867,47 @@ async fn test_long_group_name() -> Result<()> { Ok(()) } + +/// Regression test for the case +/// when Bob leaves the group, joins back and deletes the chat. +/// Previously this resulted in the group +/// never appearing again without removing Bob +/// and readding back because the group was +/// recorded in `leftgrps` for Bob and everyone else +/// thought that Bob is part of the group. +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_leftgrps() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + let bob = &tcm.bob().await; + + // Alice creates a group with Bob and Bob accepts it. + let bob_id = alice.add_or_lookup_contact_id(bob).await; + let alice_chat_id = create_group(alice, "Group").await?; + add_contact_to_chat(alice, alice_chat_id, bob_id).await?; + let alice_sent = alice.send_text(alice_chat_id, "Hi!").await; + let bob_chat_id = bob.recv_msg(&alice_sent).await.chat_id; + bob_chat_id.accept(bob).await?; + + // Bob leaves the group. + remove_contact_from_chat(bob, bob_chat_id, ContactId::SELF).await?; + let bob_sent = bob.pop_sent_msg().await; + alice.recv_msg(&bob_sent).await; + + // Alice adds Bob back, Bob recognizes that the chat is the same. + add_contact_to_chat(alice, alice_chat_id, bob_id).await?; + let alice_sent = alice.pop_sent_msg().await; + let bob_chat_id2 = bob.recv_msg(&alice_sent).await.chat_id; + assert_eq!(bob_chat_id, bob_chat_id2); + + // Bob deletes the chat. + bob_chat_id.delete(bob).await?; + let alice_sent = alice.send_text(alice_chat_id, "Hi again!").await; + let bob_chat_id3 = bob.recv_msg(&alice_sent).await.chat_id; + + // Chat ID is new, but not a trash chat. + assert_ne!(bob_chat_id3, bob_chat_id); + assert!(!bob_chat_id3.is_special()); + + Ok(()) +} diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 100c2874b..0dbec21e7 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -2562,26 +2562,12 @@ async fn create_group( let mut chat_id = None; let mut chat_id_blocked = Default::default(); - async fn self_explicitly_added( - context: &Context, - mime_parser: &&mut MimeMessage, - ) -> Result { - let ret = match mime_parser.get_header(HeaderDef::ChatGroupMemberAdded) { - Some(member_addr) => context.is_self_addr(member_addr).await?, - None => false, - }; - Ok(ret) - } - if chat_id.is_none() && !mime_parser.is_mailinglist_message() && !grpid.is_empty() && mime_parser.get_header(HeaderDef::ChatGroupName).is_some() // otherwise, a pending "quit" message may pop up && mime_parser.get_header(HeaderDef::ChatGroupMemberRemoved).is_none() - // re-create explicitly left groups only if ourself is re-added - && (!chat::is_group_explicitly_left(context, grpid).await? - || self_explicitly_added(context, &mime_parser).await?) { // Group does not exist but should be created. let grpname = mime_parser