diff --git a/src/mimefactory.rs b/src/mimefactory.rs index 27c1b5a1cc..cd9ddc6bc2 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -72,6 +72,13 @@ pub struct MimeFactory { /// Vector of pairs of past group member name and addresses. past_members: Vec<(String, String)>, + /// Timestamps of the members in the same order as in the `recipients` + /// followed by `past_members`. + /// + /// If this is not empty, its length + /// should be the sum of `recipients` and `past_members` length. + member_timestamps: Vec, + timestamp: i64, loaded: Loaded, in_reply_to: String, @@ -150,6 +157,7 @@ impl MimeFactory { let mut recipients = Vec::with_capacity(5); let mut past_members = Vec::new(); + let mut member_timestamps = Vec::new(); let mut recipient_ids = HashSet::new(); let mut req_mdn = false; @@ -190,6 +198,7 @@ impl MimeFactory { if add_timestamp >= remove_timestamp { if !recipients_contain_addr(&recipients, &addr) { recipients.push((name, addr)); + member_timestamps.push(add_timestamp); } recipient_ids.insert(id); } else { @@ -197,6 +206,7 @@ impl MimeFactory { // member is not actually part of the group. if !recipients_contain_addr(&past_members, &addr) { past_members.push((name, addr)); + member_timestamps.push(remove_timestamp); } } } @@ -204,6 +214,7 @@ impl MimeFactory { }, ) .await?; + let recipient_ids: Vec<_> = recipient_ids.into_iter().collect(); ContactId::scaleup_origin(context, &recipient_ids, Origin::OutgoingTo).await?; @@ -240,6 +251,10 @@ impl MimeFactory { }; let attach_selfavatar = Self::should_attach_selfavatar(context, &msg).await; + debug_assert!( + member_timestamps.is_empty() + || recipients.len() + past_members.len() == member_timestamps.len() + ); let factory = MimeFactory { from_addr, from_displayname, @@ -247,6 +262,7 @@ impl MimeFactory { selfstatus, recipients, past_members, + member_timestamps, timestamp: msg.timestamp_sort, loaded: Loaded::Message { msg, chat }, in_reply_to, @@ -276,6 +292,7 @@ impl MimeFactory { selfstatus: "".to_string(), recipients: vec![("".to_string(), contact.get_addr().to_string())], past_members: vec![], + member_timestamps: vec![], timestamp, loaded: Loaded::Mdn { rfc724_mid, @@ -565,7 +582,22 @@ impl MimeFactory { headers.push(Header::new_with_value("To".into(), to.clone()).unwrap()); if !past_members.is_empty() { headers.push( - Header::new_with_value("Chat-Group-Past-Members".into(), past_members.clone()).unwrap(), + Header::new_with_value("Chat-Group-Past-Members".into(), past_members.clone()) + .unwrap(), + ); + } + + if !undisclosed_recipients && !self.member_timestamps.is_empty() { + headers.push( + Header::new_with_value( + "Chat-Group-Member-Timestamps".into(), + self.member_timestamps + .iter() + .map(|ts| ts.to_string()) + .collect::>() + .join(" "), + ) + .unwrap(), ); }