diff --git a/src/chat.rs b/src/chat.rs index 91549e76c..ed2c610df 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1,5 +1,6 @@ //! # Chat module. +use std::cmp; use std::collections::{HashMap, HashSet}; use std::convert::{TryFrom, TryInto}; use std::fmt; @@ -289,6 +290,7 @@ impl ChatId { /// Create a group or mailinglist raw database record with the given parameters. /// The function does not add SELF nor checks if the record already exists. + #[allow(clippy::too_many_arguments)] pub(crate) async fn create_multiuser_record( context: &Context, chattype: Chattype, @@ -297,9 +299,10 @@ impl ChatId { create_blocked: Blocked, create_protected: ProtectionStatus, param: Option, + timestamp: i64, ) -> Result { let grpname = strip_rtlo_characters(grpname); - let smeared_time = create_smeared_timestamp(context); + let timestamp = cmp::min(timestamp, smeared_time(context)); let row_id = context.sql.insert( "INSERT INTO chats (type, name, grpid, blocked, created_timestamp, protected, param) VALUES(?, ?, ?, ?, ?, ?, ?);", @@ -308,7 +311,7 @@ impl ChatId { &grpname, grpid, create_blocked, - smeared_time, + timestamp, create_protected, param.unwrap_or_default(), ), @@ -318,7 +321,7 @@ impl ChatId { if create_protected == ProtectionStatus::Protected { chat_id - .add_protection_msg(context, ProtectionStatus::Protected, None, smeared_time) + .add_protection_msg(context, ProtectionStatus::Protected, None, timestamp) .await?; } diff --git a/src/receive_imf.rs b/src/receive_imf.rs index a669ec711..af7decca3 100644 --- a/src/receive_imf.rs +++ b/src/receive_imf.rs @@ -654,6 +654,7 @@ async fn add_parts( from_id, to_ids, &verified_encryption, + sent_timestamp, ) .await? { @@ -717,6 +718,7 @@ async fn add_parts( allow_creation, mailinglist_header, mime_parser, + sent_timestamp, ) .await? { @@ -885,6 +887,7 @@ async fn add_parts( from_id, to_ids, &verified_encryption, + sent_timestamp, ) .await? { @@ -1478,7 +1481,7 @@ async fn calc_sort_timestamp( always_sort_to_bottom: bool, incoming: bool, ) -> Result { - let mut sort_timestamp = message_timestamp; + let mut sort_timestamp = min(message_timestamp, smeared_time(context)); let last_msg_time: Option = if always_sort_to_bottom { // get newest message for this chat @@ -1515,7 +1518,7 @@ async fn calc_sort_timestamp( } } - Ok(min(sort_timestamp, smeared_time(context))) + Ok(sort_timestamp) } async fn lookup_chat_by_reply( @@ -1623,6 +1626,7 @@ async fn create_or_lookup_group( from_id: ContactId, to_ids: &[ContactId], verified_encryption: &VerifiedEncryption, + timestamp: i64, ) -> Result> { let grpid = if let Some(grpid) = try_getting_grpid(mime_parser) { grpid @@ -1635,7 +1639,7 @@ async fn create_or_lookup_group( member_ids.push(ContactId::SELF); } - let res = create_adhoc_group(context, mime_parser, create_blocked, &member_ids) + let res = create_adhoc_group(context, mime_parser, create_blocked, &member_ids, timestamp) .await .context("could not create ad hoc group")? .map(|chat_id| (chat_id, create_blocked)); @@ -1717,6 +1721,7 @@ async fn create_or_lookup_group( create_blocked, create_protected, None, + timestamp, ) .await .with_context(|| format!("Failed to create group '{grpname}' for grpid={grpid}"))?; @@ -2050,6 +2055,7 @@ async fn create_or_lookup_mailinglist( allow_creation: bool, list_id_header: &str, mime_parser: &MimeMessage, + timestamp: i64, ) -> Result> { let listid = mailinglist_header_listid(list_id_header)?; @@ -2081,6 +2087,7 @@ async fn create_or_lookup_mailinglist( blocked, ProtectionStatus::Unprotected, param, + timestamp, ) .await .with_context(|| { @@ -2265,6 +2272,7 @@ async fn create_adhoc_group( mime_parser: &MimeMessage, create_blocked: Blocked, member_ids: &[ContactId], + timestamp: i64, ) -> Result> { if mime_parser.is_mailinglist_message() { info!( @@ -2309,6 +2317,7 @@ async fn create_adhoc_group( create_blocked, ProtectionStatus::Unprotected, None, + timestamp, ) .await?; chat::add_to_chat_contacts_table(context, new_chat_id, member_ids).await?; diff --git a/src/securejoin/bob.rs b/src/securejoin/bob.rs index 9f9e25036..49dcee27a 100644 --- a/src/securejoin/bob.rs +++ b/src/securejoin/bob.rs @@ -16,7 +16,7 @@ use crate::context::Context; use crate::events::EventType; use crate::mimeparser::MimeMessage; use crate::sync::Sync::*; -use crate::tools::time; +use crate::tools::{create_smeared_timestamp, time}; use crate::{chat, stock_str}; /// Starts the securejoin protocol with the QR `invite`. @@ -192,6 +192,7 @@ impl BobState { Blocked::Not, ProtectionStatus::Unprotected, // protection is added later as needed None, + create_smeared_timestamp(context), ) .await? }