Skip to content

Commit

Permalink
feat: Don't unarchive a group on a member removal except SELF (#5618)
Browse files Browse the repository at this point in the history
  • Loading branch information
iequidoo committed Jun 21, 2024
1 parent 0983816 commit 6888326
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions src/receive_imf/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6888326

Please sign in to comment.