diff --git a/src/chat.rs b/src/chat.rs index 55264986d..4a2c33758 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -3961,6 +3961,45 @@ mod tests { Ok(()) } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] + async fn test_sync_member_list_on_rejoin() -> Result<()> { + let alice = TestContext::new_alice().await; + + let bob_id = Contact::create(&alice, "", "bob@example.net").await?; + let claire_id = Contact::create(&alice, "", "claire@example.de").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, claire_id).await?; + + send_text_msg(&alice, alice_chat_id, "populate".to_string()).await?; + let add = alice.pop_sent_msg().await; + let bob = TestContext::new_bob().await; + bob.recv_msg(&add).await; + let bob_chat_id = bob.get_last_msg().await.chat_id; + assert_eq!(get_chat_contacts(&bob, bob_chat_id).await?.len(), 3); + + // remove bob from chat + remove_contact_from_chat(&alice, alice_chat_id, bob_id).await?; + let remove_bob = alice.pop_sent_msg().await; + bob.recv_msg(&remove_bob).await; + tokio::time::sleep(std::time::Duration::from_millis(1100)).await; + + // remove any other member + remove_contact_from_chat(&alice, alice_chat_id, claire_id).await?; + alice.pop_sent_msg().await; + tokio::time::sleep(std::time::Duration::from_millis(1100)).await; + + // readd bob + add_contact_to_chat(&alice, alice_chat_id, bob_id).await?; + let add2 = alice.pop_sent_msg().await; + bob.recv_msg(&add2).await; + + // number of memebers in chat should have updated + assert_eq!(get_chat_contacts(&bob, bob_chat_id).await?.len(), 2); + Ok(()) + } + #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn test_leave_group() -> Result<()> { let alice = TestContext::new_alice().await; diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 4ce43c4b9..8a143e63e 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -1613,21 +1613,20 @@ async fn apply_group_changes( removed_id = Contact::lookup_id_by_addr(context, &removed_addr, Origin::Unknown).await?; match removed_id { Some(contact_id) => { - let mut previous_exists = false; - if let Some(msgid) = mime_parser.get_header(HeaderDef::InReplyTo) { - if rfc724_mid_exists(context, msgid).await?.is_some() { - previous_exists = true; - } - } - if mime_parser.get_header(HeaderDef::InReplyTo).is_none() || !previous_exists { - recreate_member_list = true; - } else { + recreate_member_list = match mime_parser.get_header(HeaderDef::InReplyTo) { + Some(reply_to) if rfc724_mid_exists(context, reply_to).await?.is_none() => true, + Some(_) => false, + None => true, + }; + + if !recreate_member_list { chat::remove_from_chat_contacts_table(context, chat_id, contact_id).await?; chat_id .update_timestamp(context, Param::MemberListTimestamp, sent_timestamp) .await?; send_event_chat_modified = true; } + better_msg = if contact_id == from_id { Some(stock_str::msg_group_left(context, from_id).await) } else { @@ -1650,9 +1649,13 @@ async fn apply_group_changes( if let Some(contact_id) = Contact::lookup_id_by_addr(context, &added_member, Origin::Unknown).await? { - if mime_parser.get_header(HeaderDef::InReplyTo).is_none() { - recreate_member_list = true; - } else { + recreate_member_list = match mime_parser.get_header(HeaderDef::InReplyTo) { + Some(reply_to) if rfc724_mid_exists(context, reply_to).await?.is_none() => true, + Some(_) => false, + None => true, + }; + warn!(context, "recreating: {}", recreate_member_list); + if !recreate_member_list { chat::add_to_chat_contacts_table(context, chat_id, &[contact_id]).await?; chat_id .update_timestamp(context, Param::MemberListTimestamp, sent_timestamp)