-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use 0 timestamps if Chat-Group-Member-Timestamps is not set
- Loading branch information
Showing
2 changed files
with
74 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5485,3 +5485,69 @@ async fn test_prefer_chat_group_id_over_references() -> Result<()> { | |
assert_ne!(chat1.id, chat2.id); | ||
Ok(()) | ||
} | ||
|
||
/// Tests that if member timestamps are unknown | ||
/// because of the missing `Chat-Group-Member-Timestamps` header, | ||
/// then timestamps default to zero. | ||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)] | ||
async fn test_default_member_timestamps_to_zero() -> Result<()> { | ||
let bob = &TestContext::new_bob().await; | ||
|
||
let now = time(); | ||
|
||
let date = chrono::DateTime::<chrono::Utc>::from_timestamp(now - 1000, 0) | ||
.unwrap() | ||
.to_rfc2822(); | ||
let msg = receive_imf( | ||
bob, | ||
format!( | ||
"Subject: Some group\r\n\ | ||
From: <[email protected]>\r\n\ | ||
To: <[email protected]>, <[email protected]>, <[email protected]>\r\n\ | ||
Date: {date}\r\n\ | ||
Message-ID: <first@localhost>\r\n\ | ||
Chat-Group-ID: foobarbaz12\n\ | ||
Chat-Group-Name: foo\n\ | ||
Chat-Version: 1.0\r\n\ | ||
\r\n\ | ||
Hi!\r\n" | ||
) | ||
.as_bytes(), | ||
false, | ||
) | ||
.await? | ||
.unwrap(); | ||
let chat = Chat::load_from_db(bob, msg.chat_id).await?; | ||
assert_eq!(chat.typ, Chattype::Group); | ||
assert_eq!(chat::get_chat_contacts(bob, chat.id).await?.len(), 4); | ||
|
||
let date = chrono::DateTime::<chrono::Utc>::from_timestamp(now, 0) | ||
.unwrap() | ||
.to_rfc2822(); | ||
receive_imf( | ||
bob, | ||
format!( | ||
"Subject: Some group\r\n\ | ||
From: <[email protected]>\r\n\ | ||
To: <[email protected]>, <[email protected]>\r\n\ | ||
Chat-Group-Past-Members: <[email protected]>\r\n\ | ||
Chat-Group-Member-Timestamps: 1737783000 1737783100 1737783200\r\n\ | ||
Chat-Group-ID: foobarbaz12\n\ | ||
Chat-Group-Name: foo\n\ | ||
Chat-Version: 1.0\r\n\ | ||
Date: {date}\r\n\ | ||
Message-ID: <second@localhost>\r\n\ | ||
\r\n\ | ||
Hi back!\r\n" | ||
) | ||
.as_bytes(), | ||
false, | ||
) | ||
.await? | ||
.unwrap(); | ||
|
||
let chat = Chat::load_from_db(bob, msg.chat_id).await?; | ||
assert_eq!(chat.typ, Chattype::Group); | ||
assert_eq!(chat::get_chat_contacts(bob, chat.id).await?.len(), 3); | ||
Ok(()) | ||
} |