Skip to content

Commit

Permalink
Send Chat-Group-Member-Timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Jan 5, 2025
1 parent f7300eb commit 64bbd7e
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/mimefactory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i64>,

timestamp: i64,
loaded: Loaded,
in_reply_to: String,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -190,20 +198,23 @@ 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 {
// Row is a tombstone,
// 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);
}
}
}
Ok(())
},
)
.await?;

let recipient_ids: Vec<_> = recipient_ids.into_iter().collect();
ContactId::scaleup_origin(context, &recipient_ids, Origin::OutgoingTo).await?;

Expand Down Expand Up @@ -240,13 +251,18 @@ 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,
sender_displayname,
selfstatus,
recipients,
past_members,
member_timestamps,
timestamp: msg.timestamp_sort,
loaded: Loaded::Message { msg, chat },
in_reply_to,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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::<Vec<String>>()
.join(" "),
)
.unwrap(),
);
}

Expand Down

0 comments on commit 64bbd7e

Please sign in to comment.