diff --git a/src/receive_imf.rs b/src/receive_imf.rs index f837dcdd9..8d9339189 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -2333,6 +2333,19 @@ async fn apply_group_changes( context, "Recreating chat {chat_id} member list with {new_members:?}.", ); + if !self_added + && (chat.blocked == Blocked::Request || !chat_contacts.contains(&ContactId::SELF)) + { + warn!(context, "Implicit addition of SELF to chat {chat_id}."); + group_changes_msgs.push( + stock_str::msg_add_member_local( + context, + &context.get_primary_self_addr().await?, + ContactId::UNDEFINED, + ) + .await, + ); + } } if new_members != chat_contacts { diff --git a/src/receive_imf/tests.rs b/src/receive_imf/tests.rs index 07e9e7259..4c1a3f84a 100644 --- a/src/receive_imf/tests.rs +++ b/src/receive_imf/tests.rs @@ -4447,6 +4447,20 @@ async fn test_recreate_member_list_on_missing_add_of_self() -> Result<()> { send_text_msg(&alice, alice_chat_id, "4th message".to_string()).await?; bob.recv_msg(&alice.pop_sent_msg().await).await; assert!(!is_contact_in_chat(&bob, bob_chat_id, ContactId::SELF).await?); + + // But if Bob left a long time ago, they must recreate the member list after missing a message. + SystemTime::shift(Duration::from_secs(3600)); + send_text_msg(&alice, alice_chat_id, "5th message".to_string()).await?; + alice.pop_sent_msg().await; + send_text_msg(&alice, alice_chat_id, "6th message".to_string()).await?; + bob.recv_msg(&alice.pop_sent_msg().await).await; + assert!(is_contact_in_chat(&bob, bob_chat_id, ContactId::SELF).await?); + + bob.golden_test_chat( + bob_chat_id, + "receive_imf_recreate_member_list_on_missing_add_of_self", + ) + .await; Ok(()) } diff --git a/test-data/golden/receive_imf_recreate_member_list_on_missing_add_of_self b/test-data/golden/receive_imf_recreate_member_list_on_missing_add_of_self new file mode 100644 index 000000000..d1995d0a8 --- /dev/null +++ b/test-data/golden/receive_imf_recreate_member_list_on_missing_add_of_self @@ -0,0 +1,9 @@ +Group#Chat#10: Group [2 member(s)] +-------------------------------------------------------------------------------- +Msg#10: info (Contact#Contact#Info): Member Me (bob@example.net) added. [NOTICED][INFO] +Msg#11: (Contact#Contact#10): second message [FRESH] +Msg#12🔒: Me (Contact#Contact#Self): You left the group. [INFO] √ +Msg#13: (Contact#Contact#10): 4th message [FRESH] +Msg#14: info (Contact#Contact#Info): Member Me (bob@example.net) added. [NOTICED][INFO] +Msg#15: (Contact#Contact#10): 6th message [FRESH] +--------------------------------------------------------------------------------