Skip to content

Commit

Permalink
fix: use member list timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Jan 16, 2025
1 parent 8336f9d commit 47afba6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,22 @@ impl ChatId {
Ok(self.get_param(context).await?.exists(Param::Devicetalk))
}

/// Returns chat member list timestamp.
pub(crate) async fn member_list_timestamp(self, context: &Context) -> Result<i64> {
let creation_timestamp: i64 = context
.sql
.query_get_value("SELECT created_timestamp FROM chats WHERE id=?", (self,))
.await
.context("SQL error querying created_timestamp")?
.context("Chat not found")?;

Ok(self
.get_param(context)
.await?
.get_i64(Param::MemberListTimestamp)
.unwrap_or(creation_timestamp))
}

async fn parent_query<T, F>(
self,
context: &Context,
Expand Down
14 changes: 12 additions & 2 deletions src/mimefactory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tokio::fs;
use crate::blob::BlobObject;
use crate::chat::{self, Chat};
use crate::config::Config;
use crate::constants::{Chattype, DC_FROM_HANDSHAKE};
use crate::constants::{Chattype, DC_FROM_HANDSHAKE, TIMESTAMP_SENT_TOLERANCE};
use crate::contact::{Contact, ContactId, Origin};
use crate::context::Context;
use crate::e2ee::EncryptHelper;
Expand Down Expand Up @@ -621,7 +621,17 @@ impl MimeFactory {
);
}

if !self.member_timestamps.is_empty() {
let chat_memberlist_is_stale = if let Loaded::Message { chat, .. } = &self.loaded {
let now = time();
let member_list_ts = chat.id.member_list_timestamp(context).await?;
member_list_ts > 0
&& now.saturating_add(TIMESTAMP_SENT_TOLERANCE)
>= member_list_ts.saturating_add(60 * 24 * 3600)
} else {
false
};

if !self.member_timestamps.is_empty() && !chat_memberlist_is_stale {
headers.push(
Header::new_with_value(
"Chat-Group-Member-Timestamps".into(),
Expand Down
2 changes: 0 additions & 2 deletions src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ pub enum Param {
GroupNameTimestamp = b'g',

/// For Chats: timestamp of member list update.
///
/// Deprecated 2025-01-07.
MemberListTimestamp = b'k',

/// For Webxdc Message Instances: Current document name
Expand Down
8 changes: 8 additions & 0 deletions src/receive_imf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2395,6 +2395,14 @@ async fn apply_group_changes(
send_event_chat_modified = true;
}
}

chat_id
.update_timestamp(
context,
Param::MemberListTimestamp,
mime_parser.timestamp_sent,
)
.await?;
}

if let Some(added_id) = added_id {
Expand Down

0 comments on commit 47afba6

Please sign in to comment.