From de3a50eecbf76c02ea9c0cf83e4280d8cb03fcd6 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Wed, 13 Nov 2024 20:06:41 -0300 Subject: [PATCH] fix: Add self-addition message to chat when recreating member list A user reported to me that after they left a group, they were implicitly readded, but there's no any readdition message, so currently it looks in the chat like leaving it has no effect, just new messages continue to arrive. The readdition probably happened because some member didn't receive the user's self-removal message, anyway, at least there must be a message that the user is readded, even if it isn't known by whom. --- src/receive_imf.rs | 13 +++++++++++++ src/receive_imf/tests.rs | 14 ++++++++++++++ ...imf_recreate_member_list_on_missing_add_of_self | 9 +++++++++ 3 files changed, 36 insertions(+) create mode 100644 test-data/golden/receive_imf_recreate_member_list_on_missing_add_of_self diff --git a/src/receive_imf.rs b/src/receive_imf.rs index f837dcdd9d..8d9339189e 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 c87d3c1831..6f75c903ae 100644 --- a/src/receive_imf/tests.rs +++ b/src/receive_imf/tests.rs @@ -4455,6 +4455,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 0000000000..d1995d0a82 --- /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] +--------------------------------------------------------------------------------