mirror of
https://github.com/chatmail/core.git
synced 2026-05-03 05:16:28 +03:00
fix: do not apply group changes to special chats
This is a similar check to the one we have in `save_locations`.
This commit is contained in:
@@ -1723,6 +1723,10 @@ async fn apply_group_changes(
|
|||||||
to_ids: &[ContactId],
|
to_ids: &[ContactId],
|
||||||
is_partial_download: bool,
|
is_partial_download: bool,
|
||||||
) -> Result<Vec<String>> {
|
) -> Result<Vec<String>> {
|
||||||
|
if chat_id.is_special() {
|
||||||
|
// Do not apply group changes to the trash chat.
|
||||||
|
return Ok(Vec::new());
|
||||||
|
}
|
||||||
let mut chat = Chat::load_from_db(context, chat_id).await?;
|
let mut chat = Chat::load_from_db(context, chat_id).await?;
|
||||||
if chat.typ != Chattype::Group {
|
if chat.typ != Chattype::Group {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
|
|||||||
@@ -3686,6 +3686,34 @@ async fn test_mua_can_readd() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
|
async fn test_member_left_does_not_create_chat() -> Result<()> {
|
||||||
|
let alice = TestContext::new_alice().await;
|
||||||
|
let bob = TestContext::new_bob().await;
|
||||||
|
let alice_chat_id = create_group_chat(&alice, ProtectionStatus::Unprotected, "Group").await?;
|
||||||
|
add_contact_to_chat(
|
||||||
|
&alice,
|
||||||
|
alice_chat_id,
|
||||||
|
Contact::create(&alice, "bob", &bob.get_config(Config::Addr).await?.unwrap()).await?,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
send_text_msg(&alice, alice_chat_id, "populate".to_string()).await?;
|
||||||
|
alice.pop_sent_msg().await;
|
||||||
|
|
||||||
|
// Bob only received a message of Alice leaving the group.
|
||||||
|
// This should not create the group.
|
||||||
|
//
|
||||||
|
// The reason is to avoid recreating deleted chats,
|
||||||
|
// especially the chats that were created due to "split group" bugs
|
||||||
|
// which some members simply deleted and some members left,
|
||||||
|
// recreating the chat for others.
|
||||||
|
remove_contact_from_chat(&alice, alice_chat_id, ContactId::SELF).await?;
|
||||||
|
let bob_chat_id = bob.recv_msg(&alice.pop_sent_msg().await).await.chat_id;
|
||||||
|
assert!(bob_chat_id.is_trash());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn test_recreate_member_list_on_missing_add_of_self() -> Result<()> {
|
async fn test_recreate_member_list_on_missing_add_of_self() -> Result<()> {
|
||||||
let alice = TestContext::new_alice().await;
|
let alice = TestContext::new_alice().await;
|
||||||
@@ -3699,11 +3727,14 @@ async fn test_recreate_member_list_on_missing_add_of_self() -> Result<()> {
|
|||||||
.await?;
|
.await?;
|
||||||
send_text_msg(&alice, alice_chat_id, "populate".to_string()).await?;
|
send_text_msg(&alice, alice_chat_id, "populate".to_string()).await?;
|
||||||
alice.pop_sent_msg().await;
|
alice.pop_sent_msg().await;
|
||||||
remove_contact_from_chat(&alice, alice_chat_id, ContactId::SELF).await?;
|
|
||||||
|
send_text_msg(&alice, alice_chat_id, "second message".to_string()).await?;
|
||||||
|
|
||||||
let bob_chat_id = bob.recv_msg(&alice.pop_sent_msg().await).await.chat_id;
|
let bob_chat_id = bob.recv_msg(&alice.pop_sent_msg().await).await.chat_id;
|
||||||
|
assert!(!bob_chat_id.is_special());
|
||||||
|
|
||||||
// Bob missed the message adding them, but must recreate the member list.
|
// Bob missed the message adding them, but must recreate the member list.
|
||||||
assert_eq!(get_chat_contacts(&bob, bob_chat_id).await?.len(), 1);
|
assert_eq!(get_chat_contacts(&bob, bob_chat_id).await?.len(), 2);
|
||||||
assert!(is_contact_in_chat(&bob, bob_chat_id, ContactId::SELF).await?);
|
assert!(is_contact_in_chat(&bob, bob_chat_id, ContactId::SELF).await?);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user