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 6, 2024
1 parent 1a15fef commit 81efe7c
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 @@ -1648,7 +1648,13 @@ RETURNING id
replace_msg_id.trash(context).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 @@ -4567,6 +4567,40 @@ Chat-Group-Member-Removed: [email protected]",
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, "", "[email protected]").await?;
let fiona_id = Contact::create(alice, "", "[email protected]").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 81efe7c

Please sign in to comment.