From 6888326ad3bea205ab05a5812d03dcf6b5b9ce94 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Fri, 24 May 2024 20:36:24 -0300 Subject: [PATCH] feat: Don't unarchive a group on a member removal except SELF (#5618) --- src/receive_imf.rs | 8 +++++++- src/receive_imf/tests.rs | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 468b37716c..5a0f062ef7 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1659,7 +1659,13 @@ RETURNING id replace_msg_id.trash(context, on_server).await?; } - chat_id.unarchive_if_not_muted(context, state).await?; + let unarchive = match mime_parser.get_header(HeaderDef::ChatGroupMemberRemoved) { + Some(addr) => context.is_self_addr(addr).await?, + None => true, + }; + if unarchive { + chat_id.unarchive_if_not_muted(context, state).await?; + } info!( context, diff --git a/src/receive_imf/tests.rs b/src/receive_imf/tests.rs index c9223c6e6b..3428483d05 100644 --- a/src/receive_imf/tests.rs +++ b/src/receive_imf/tests.rs @@ -4647,6 +4647,40 @@ Chat-Group-Member-Removed: charlie@example.com", Ok(()) } +#[tokio::test(flavor = "multi_thread", worker_threads = 2)] +async fn test_unarchive_on_member_removal() -> Result<()> { + let mut tcm = TestContextManager::new(); + let alice = &tcm.alice().await; + let bob = &tcm.bob().await; + let bob_id = Contact::create(alice, "", "bob@example.net").await?; + let fiona_id = Contact::create(alice, "", "fiona@example.net").await?; + let alice_chat_id = create_group_chat(alice, ProtectionStatus::Unprotected, "foos").await?; + add_contact_to_chat(alice, alice_chat_id, bob_id).await?; + add_contact_to_chat(alice, alice_chat_id, fiona_id).await?; + + send_text_msg(alice, alice_chat_id, "populate".to_string()).await?; + let msg = alice.pop_sent_msg().await; + bob.recv_msg(&msg).await; + let bob_chat_id = bob.get_last_msg().await.chat_id; + bob_chat_id + .set_visibility(bob, ChatVisibility::Archived) + .await?; + + remove_contact_from_chat(alice, alice_chat_id, fiona_id).await?; + let msg = alice.pop_sent_msg().await; + bob.recv_msg(&msg).await; + let bob_chat = Chat::load_from_db(bob, bob_chat_id).await?; + assert_eq!(bob_chat.get_visibility(), ChatVisibility::Archived); + + remove_contact_from_chat(alice, alice_chat_id, bob_id).await?; + let msg = alice.pop_sent_msg().await; + bob.recv_msg(&msg).await; + let bob_chat = Chat::load_from_db(bob, bob_chat_id).await?; + assert_eq!(bob_chat.get_visibility(), ChatVisibility::Normal); + + Ok(()) +} + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_forged_from() -> Result<()> { let mut tcm = TestContextManager::new();