From 81695d6b80f851be8c0a849562470e0a827f4547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Kl=C3=A4hn?= Date: Fri, 2 Dec 2022 19:53:57 +0100 Subject: [PATCH] don't always build new contact list --- src/mimeparser.rs | 2 ++ src/receive_imf.rs | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/mimeparser.rs b/src/mimeparser.rs index 843053930..9b5cef642 100644 --- a/src/mimeparser.rs +++ b/src/mimeparser.rs @@ -57,6 +57,8 @@ pub struct MimeMessage { /// Whether the From address was repeated in the signed part /// (and we know that the signer intended to send from this address) pub from_is_signed: bool, + /// The list post message is only set for messaging lists and is the address + /// where users can send messages to which will be posted in the list pub list_post: Option, pub chat_disposition_notification_to: Option, pub decryption_info: DecryptionInfo, diff --git a/src/receive_imf.rs b/src/receive_imf.rs index 41bb20ff9..50ce350a6 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -12,7 +12,10 @@ use num_traits::FromPrimitive; use once_cell::sync::Lazy; use regex::Regex; -use crate::chat::{self, Chat, ChatId, ChatIdBlocked, ProtectionStatus}; +use crate::chat::{ + self, add_contact_to_chat, remove_contact_from_chat, Chat, ChatId, ChatIdBlocked, + ProtectionStatus, +}; use crate::config::Config; use crate::constants::{Blocked, Chattype, ShowEmails, DC_CHAT_ID_TRASH}; use crate::contact::{ @@ -1611,9 +1614,13 @@ async fn apply_group_changes( .cloned() { removed_id = Contact::lookup_id_by_addr(context, &removed_addr, Origin::Unknown).await?; - recreate_member_list = true; match removed_id { Some(contact_id) => { + if mime_parser.get_header(HeaderDef::InReplyTo).is_none() { + recreate_member_list = true; + } else { + remove_contact_from_chat(context, chat_id, contact_id).await? + } better_msg = if contact_id == from_id { Some(stock_str::msg_group_left(context, from_id).await) } else { @@ -1621,7 +1628,7 @@ async fn apply_group_changes( }; } None => warn!(context, "removed {:?} has no contact_id", removed_addr), - } + }; } else { removed_id = None; if let Some(added_member) = mime_parser @@ -1629,7 +1636,18 @@ async fn apply_group_changes( .cloned() { better_msg = Some(stock_str::msg_add_member(context, &added_member, from_id).await); - recreate_member_list = true; + + if let Some(contact_id) = + Contact::lookup_id_by_addr(context, &added_member, Origin::Unknown).await? + { + if mime_parser.get_header(HeaderDef::InReplyTo).is_none() { + recreate_member_list = true; + } else { + add_contact_to_chat(context, chat_id, contact_id).await? + } + } else { + recreate_member_list = true; + } } else if let Some(old_name) = mime_parser .get_header(HeaderDef::ChatGroupNameChanged) // See create_or_lookup_group() for explanation