From 1dbf924c6a05ba358ec39f5db5288f4b39a04cf9 Mon Sep 17 00:00:00 2001 From: iequidoo Date: Thu, 18 Jan 2024 21:29:42 -0300 Subject: [PATCH] feat: chat::resend_msgs: Guarantee strictly increasing time in the Date header Use `create_smeared_timestamp()` for this. This allows to dedup messages on the receiver -- if it sees the same Message-ID, but a different timestamp, then it's a resent message that can be deleted. --- src/chat.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/chat.rs b/src/chat.rs index 7985149fb..b49e1bcc0 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -4076,6 +4076,7 @@ pub async fn resend_msgs(context: &Context, msg_ids: &[MsgId]) -> Result<()> { chat_id: msg.chat_id, msg_id: msg.id, }); + msg.timestamp_sort = create_smeared_timestamp(context); if !create_send_msg_jobs(context, &mut msg).await?.is_empty() { context.scheduler.interrupt_smtp().await; } @@ -6502,6 +6503,7 @@ mod tests { // Bob receives all messages let bob = TestContext::new_bob().await; let msg = bob.recv_msg(&sent1).await; + let sent1_ts_sent = msg.timestamp_sent; assert_eq!(msg.get_text(), "alice->bob"); assert_eq!(get_chat_contacts(&bob, msg.chat_id).await?.len(), 2); assert_eq!(get_chat_msgs(&bob, msg.chat_id).await?.len(), 1); @@ -6524,6 +6526,7 @@ mod tests { assert_eq!(get_chat_msgs(&claire, msg.chat_id).await?.len(), 2); let msg_from = Contact::get_by_id(&claire, msg.get_from_id()).await?; assert_eq!(msg_from.get_addr(), "alice@example.org"); + assert!(sent1_ts_sent < msg.timestamp_sent); Ok(()) }