Skip to content

Commit d7aecab

Browse files
committed
fix: do not apply group changes to special chats
This is a similar check to the one we have in `save_locations`.
1 parent 9ca0490 commit d7aecab

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

src/receive_imf.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,10 @@ async fn apply_group_changes(
17231723
to_ids: &[ContactId],
17241724
is_partial_download: bool,
17251725
) -> Result<Vec<String>> {
1726+
if chat_id.is_special() {
1727+
// Do not apply group changes to the trash chat.
1728+
return Ok(Vec::new());
1729+
}
17261730
let mut chat = Chat::load_from_db(context, chat_id).await?;
17271731
if chat.typ != Chattype::Group {
17281732
return Ok(Vec::new());

src/receive_imf/tests.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3687,7 +3687,7 @@ async fn test_mua_can_readd() -> Result<()> {
36873687
}
36883688

36893689
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
3690-
async fn test_recreate_member_list_on_missing_add_of_self() -> Result<()> {
3690+
async fn test_member_left_does_not_create_chat() -> Result<()> {
36913691
let alice = TestContext::new_alice().await;
36923692
let bob = TestContext::new_bob().await;
36933693
let alice_chat_id = create_group_chat(&alice, ProtectionStatus::Unprotected, "Group").await?;
@@ -3699,11 +3699,42 @@ async fn test_recreate_member_list_on_missing_add_of_self() -> Result<()> {
36993699
.await?;
37003700
send_text_msg(&alice, alice_chat_id, "populate".to_string()).await?;
37013701
alice.pop_sent_msg().await;
3702+
3703+
// Bob only received a message of Alice leaving the group.
3704+
// This should not create the group.
3705+
//
3706+
// The reason is to avoid recreating deleted chats,
3707+
// especially the chats that were created due to "split group" bugs
3708+
// which some members simply deleted and some members left,
3709+
// recreating the chat for others.
37023710
remove_contact_from_chat(&alice, alice_chat_id, ContactId::SELF).await?;
37033711
let bob_chat_id = bob.recv_msg(&alice.pop_sent_msg().await).await.chat_id;
3712+
assert!(bob_chat_id.is_trash());
3713+
3714+
Ok(())
3715+
}
3716+
3717+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
3718+
async fn test_recreate_member_list_on_missing_add_of_self() -> Result<()> {
3719+
let alice = TestContext::new_alice().await;
3720+
let bob = TestContext::new_bob().await;
3721+
let alice_chat_id = create_group_chat(&alice, ProtectionStatus::Unprotected, "Group").await?;
3722+
add_contact_to_chat(
3723+
&alice,
3724+
alice_chat_id,
3725+
Contact::create(&alice, "bob", &bob.get_config(Config::Addr).await?.unwrap()).await?,
3726+
)
3727+
.await?;
3728+
send_text_msg(&alice, alice_chat_id, "populate".to_string()).await?;
3729+
alice.pop_sent_msg().await;
3730+
3731+
send_text_msg(&alice, alice_chat_id, "second message".to_string()).await?;
3732+
3733+
let bob_chat_id = bob.recv_msg(&alice.pop_sent_msg().await).await.chat_id;
3734+
assert!(!bob_chat_id.is_special());
37043735

37053736
// Bob missed the message adding them, but must recreate the member list.
3706-
assert_eq!(get_chat_contacts(&bob, bob_chat_id).await?.len(), 1);
3737+
assert_eq!(get_chat_contacts(&bob, bob_chat_id).await?.len(), 2);
37073738
assert!(is_contact_in_chat(&bob, bob_chat_id, ContactId::SELF).await?);
37083739
Ok(())
37093740
}

0 commit comments

Comments
 (0)