Skip to content

Commit 104cc3a

Browse files
committed
fix: use 0 timestamps if Chat-Group-Member-Timestamps is not set
1 parent fc06351 commit 104cc3a

File tree

2 files changed

+74
-7
lines changed

2 files changed

+74
-7
lines changed

src/receive_imf.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2093,13 +2093,14 @@ async fn create_group(
20932093
}
20942094
members.extend(to_ids);
20952095

2096-
chat::add_to_chat_contacts_table(
2097-
context,
2098-
mime_parser.timestamp_sent,
2099-
new_chat_id,
2100-
&members,
2101-
)
2102-
.await?;
2096+
// Add all members with 0 timestamp
2097+
// because we don't know the real timestamp of their addition.
2098+
// This will allow other senders who support
2099+
// `Chat-Group-Member-Timestamps` to overwrite
2100+
// timestamps later.
2101+
let timestamp = 0;
2102+
2103+
chat::add_to_chat_contacts_table(context, timestamp, new_chat_id, &members).await?;
21032104
}
21042105

21052106
context.emit_event(EventType::ChatModified(new_chat_id));

src/receive_imf/receive_imf_tests.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5485,3 +5485,69 @@ async fn test_prefer_chat_group_id_over_references() -> Result<()> {
54855485
assert_ne!(chat1.id, chat2.id);
54865486
Ok(())
54875487
}
5488+
5489+
/// Tests that if member timestamps are unknown
5490+
/// because of the missing `Chat-Group-Member-Timestamps` header,
5491+
/// then timestamps default to zero.
5492+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
5493+
async fn test_default_member_timestamps_to_zero() -> Result<()> {
5494+
let bob = &TestContext::new_bob().await;
5495+
5496+
let now = time();
5497+
5498+
let date = chrono::DateTime::<chrono::Utc>::from_timestamp(now - 1000, 0)
5499+
.unwrap()
5500+
.to_rfc2822();
5501+
let msg = receive_imf(
5502+
bob,
5503+
format!(
5504+
"Subject: Some group\r\n\
5505+
From: <alice@example.org>\r\n\
5506+
To: <bob@example.net>, <claire@example.org>, <fiona@example.org>\r\n\
5507+
Date: {date}\r\n\
5508+
Message-ID: <first@localhost>\r\n\
5509+
Chat-Group-ID: foobarbaz12\n\
5510+
Chat-Group-Name: foo\n\
5511+
Chat-Version: 1.0\r\n\
5512+
\r\n\
5513+
Hi!\r\n"
5514+
)
5515+
.as_bytes(),
5516+
false,
5517+
)
5518+
.await?
5519+
.unwrap();
5520+
let chat = Chat::load_from_db(bob, msg.chat_id).await?;
5521+
assert_eq!(chat.typ, Chattype::Group);
5522+
assert_eq!(chat::get_chat_contacts(bob, chat.id).await?.len(), 4);
5523+
5524+
let date = chrono::DateTime::<chrono::Utc>::from_timestamp(now, 0)
5525+
.unwrap()
5526+
.to_rfc2822();
5527+
receive_imf(
5528+
bob,
5529+
format!(
5530+
"Subject: Some group\r\n\
5531+
From: <claire@example.org>\r\n\
5532+
To: <alice@example.org>, <bob@example.net>\r\n\
5533+
Chat-Group-Past-Members: <fiona@example.org>\r\n\
5534+
Chat-Group-Member-Timestamps: 1737783000 1737783100 1737783200\r\n\
5535+
Chat-Group-ID: foobarbaz12\n\
5536+
Chat-Group-Name: foo\n\
5537+
Chat-Version: 1.0\r\n\
5538+
Date: {date}\r\n\
5539+
Message-ID: <second@localhost>\r\n\
5540+
\r\n\
5541+
Hi back!\r\n"
5542+
)
5543+
.as_bytes(),
5544+
false,
5545+
)
5546+
.await?
5547+
.unwrap();
5548+
5549+
let chat = Chat::load_from_db(bob, msg.chat_id).await?;
5550+
assert_eq!(chat.typ, Chattype::Group);
5551+
assert_eq!(chat::get_chat_contacts(bob, chat.id).await?.len(), 3);
5552+
Ok(())
5553+
}

0 commit comments

Comments
 (0)