Skip to content

Commit

Permalink
fix: only send Chat-Group-Member-Timestamps in groups
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Jan 25, 2025
1 parent 787f54f commit fc06351
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 19 deletions.
13 changes: 12 additions & 1 deletion src/chat/chat_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2495,7 +2495,9 @@ async fn test_broadcast() -> Result<()> {
}

{
let msg = bob.recv_msg(&alice.pop_sent_msg().await).await;
let sent_msg = alice.pop_sent_msg().await;
assert!(!sent_msg.payload.contains("Chat-Group-Member-Timestamps:"));
let msg = bob.recv_msg(&sent_msg).await;
assert_eq!(msg.get_text(), "ola!");
assert_eq!(msg.subject, "Broadcast list");
assert!(!msg.get_showpadlock()); // avoid leaking recipients in encryption data
Expand Down Expand Up @@ -3536,3 +3538,12 @@ async fn test_restore_backup_after_60_days() -> Result<()> {

Ok(())
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn test_one_to_one_chat_no_group_member_timestamps() {
let t = TestContext::new_alice().await;
let chat = t.create_chat_with_contact("bob", "[email protected]").await;
let sent = t.send_text(chat.id, "Hi!").await;
let payload = sent.payload;
assert!(!payload.contains("Chat-Group-Member-Timestamps:"));
}
35 changes: 17 additions & 18 deletions src/mimefactory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,24 +622,23 @@ impl MimeFactory {
);
}

let chat_memberlist_is_stale = if let Loaded::Message { chat, .. } = &self.loaded {
chat.member_list_is_stale(context).await?
} else {
false
};

if !self.member_timestamps.is_empty() && !chat_memberlist_is_stale {
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(),
);
if let Loaded::Message { chat, .. } = &self.loaded {
if chat.typ == Chattype::Group
&& !self.member_timestamps.is_empty()
&& !chat.member_list_is_stale(context).await?
{
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(),
);
}
}

let subject_str = self.subject_str(context).await?;
Expand Down

0 comments on commit fc06351

Please sign in to comment.