feat: Don't send a notification when a group member left (#6575)

When there is a broken group (which might happen with multi-transport),
people want to leave it.

The problem is that every "Group left" message notifies all other
members and pops up the chat, so that other members also want to leave
the group.

This PR makes it so that "Group left" messages don't create a
notification, don't cause a number-in-a-cirle badge counter on the chat,
and don't sort up the chat in the chatlist.

If a group is deleted, then the group won't pop up when someone leaves
it; this worked fine already before this PR, and there also is a test
for it.
This commit is contained in:
Hocuri
2025-02-26 19:00:46 +01:00
committed by GitHub
parent 8ffdd55f79
commit a4e478a071
6 changed files with 137 additions and 45 deletions

View File

@@ -695,16 +695,45 @@ async fn test_leave_group() -> Result<()> {
assert_eq!(get_chat_contacts(&alice, alice_chat_id).await?.len(), 2);
// Clear events so that we can later check
// that the 'Group left' message didn't trigger IncomingMsg:
alice.evtracker.clear_events();
// Shift the time so that we can later check the 'Group left' message's timestamp:
SystemTime::shift(Duration::from_secs(60));
// Bob leaves the group.
let bob_chat_id = bob_msg.chat_id;
bob_chat_id.accept(&bob).await?;
remove_contact_from_chat(&bob, bob_chat_id, ContactId::SELF).await?;
let leave_msg = bob.pop_sent_msg().await;
alice.recv_msg(&leave_msg).await;
let rcvd_leave_msg = alice.recv_msg(&leave_msg).await;
assert_eq!(get_chat_contacts(&alice, alice_chat_id).await?.len(), 1);
assert_eq!(rcvd_leave_msg.state, MessageState::InSeen);
alice.emit_event(EventType::Test);
alice
.evtracker
.get_matching(|ev| match ev {
EventType::Test => true,
EventType::IncomingMsg { .. } => panic!("'Group left' message should be silent"),
EventType::MsgsNoticed(..) => {
panic!("'Group left' message shouldn't clear notifications")
}
_ => false,
})
.await;
// The 'Group left' message timestamp should be the same as the previous message in the chat
// so that the chat is not popped up in the chatlist:
assert_eq!(
sent_msg.load_from_db().await.timestamp_sort,
rcvd_leave_msg.timestamp_sort
);
Ok(())
}