diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 86ae562d2a..89714b22d5 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -2866,15 +2866,6 @@ async fn apply_group_changes( let (mut removed_id, mut added_id) = (None, None); let mut better_msg = None; let mut silent = false; - - // True if a Delta Chat client has explicitly added our current primary address. - let self_added = - if let Some(added_addr) = mime_parser.get_header(HeaderDef::ChatGroupMemberAdded) { - addr_cmp(&context.get_primary_self_addr().await?, added_addr) - } else { - false - }; - let chat_contacts = HashSet::::from_iter(chat::get_chat_contacts(context, chat.id).await?); let is_from_in_chat = @@ -3004,6 +2995,15 @@ async fn apply_group_changes( .await?; } else { let mut new_members: HashSet; + // True if a Delta Chat client has explicitly and really added our primary address to an + // already existing group. + let self_added = + if let Some(added_addr) = mime_parser.get_header(HeaderDef::ChatGroupMemberAdded) { + addr_cmp(&context.get_primary_self_addr().await?, added_addr) + && !chat_contacts.contains(&ContactId::SELF) + } else { + false + }; if self_added { new_members = HashSet::from_iter(to_ids_flat.iter().copied()); new_members.insert(ContactId::SELF); @@ -3070,17 +3070,18 @@ async fn apply_group_changes( .collect(); if let Some(added_id) = added_id { - if !added_ids.remove(&added_id) && !self_added { - // No-op "Member added" message. - // - // Trash it. + if !added_ids.remove(&added_id) && added_id != ContactId::SELF { + // No-op "Member added" message. An exception is self-addition messages because they at + // least must be shown when a chat is created on our side. better_msg = Some(String::new()); } } if let Some(removed_id) = removed_id { removed_ids.remove(&removed_id); } - let group_changes_msgs = if self_added { + let group_changes_msgs = if !chat_contacts.contains(&ContactId::SELF) + && new_chat_contacts.contains(&ContactId::SELF) + { Vec::new() } else { group_changes_msgs(context, &added_ids, &removed_ids, chat.id).await? diff --git a/src/tests/verified_chats.rs b/src/tests/verified_chats.rs index 2a85dbc026..ebfb85ce07 100644 --- a/src/tests/verified_chats.rs +++ b/src/tests/verified_chats.rs @@ -799,7 +799,12 @@ async fn test_verified_chat_editor_reordering() -> Result<()> { tcm.section("Charlie receives member added message"); charlie.recv_msg(&sent_member_added_msg).await; - + charlie + .golden_test_chat( + charlie_received_xdc.chat_id, + "verified_chats_editor_reordering", + ) + .await; Ok(()) } diff --git a/test-data/golden/verified_chats_editor_reordering b/test-data/golden/verified_chats_editor_reordering new file mode 100644 index 0000000000..21b949fb2b --- /dev/null +++ b/test-data/golden/verified_chats_editor_reordering @@ -0,0 +1,11 @@ +Group#Chat#11: Group [3 member(s)] 🛡️ +-------------------------------------------------------------------------------- +Msg#11: info (Contact#Contact#Info): alice@example.org invited you to join this group. + +Waiting for the device of alice@example.org to reply… [NOTICED][INFO] +Msg#13: info (Contact#Contact#Info): alice@example.org replied, waiting for being added to the group… [NOTICED][INFO] +Msg#16🔒: (Contact#Contact#11): [FRESH] +Msg#18: info (Contact#Contact#Info): Messages are end-to-end encrypted. [NOTICED][INFO 🛡️] +Msg#19: info (Contact#Contact#Info): Member bob@example.net added. [NOTICED][INFO] +Msg#20🔒: (Contact#Contact#10): Member Me added by alice@example.org. [FRESH][INFO] +--------------------------------------------------------------------------------