Skip to content

Commit bf33b95

Browse files
committed
fix: use member list timestamp
1 parent ee51911 commit bf33b95

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

src/chat.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,22 @@ impl ChatId {
12211221
Ok(self.get_param(context).await?.exists(Param::Devicetalk))
12221222
}
12231223

1224+
/// Returns chat member list timestamp.
1225+
pub(crate) async fn member_list_timestamp(self, context: &Context) -> Result<i64> {
1226+
let creation_timestamp: i64 = context
1227+
.sql
1228+
.query_get_value("SELECT created_timestamp FROM chats WHERE id=?", (self,))
1229+
.await
1230+
.context("SQL error querying created_timestamp")?
1231+
.context("Chat not found")?;
1232+
1233+
Ok(self
1234+
.get_param(context)
1235+
.await?
1236+
.get_i64(Param::MemberListTimestamp)
1237+
.unwrap_or(creation_timestamp))
1238+
}
1239+
12241240
async fn parent_query<T, F>(
12251241
self,
12261242
context: &Context,

src/mimefactory.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tokio::fs;
1212
use crate::blob::BlobObject;
1313
use crate::chat::{self, Chat};
1414
use crate::config::Config;
15-
use crate::constants::{Chattype, DC_FROM_HANDSHAKE};
15+
use crate::constants::{Chattype, DC_FROM_HANDSHAKE, TIMESTAMP_SENT_TOLERANCE};
1616
use crate::contact::{Contact, ContactId, Origin};
1717
use crate::context::Context;
1818
use crate::e2ee::EncryptHelper;
@@ -621,7 +621,17 @@ impl MimeFactory {
621621
);
622622
}
623623

624-
if !self.member_timestamps.is_empty() {
624+
let chat_memberlist_is_stale = if let Loaded::Message { chat, .. } = &self.loaded {
625+
let now = time();
626+
let member_list_ts = chat.id.member_list_timestamp(context).await?;
627+
member_list_ts > 0
628+
&& now.saturating_add(TIMESTAMP_SENT_TOLERANCE)
629+
>= member_list_ts.saturating_add(60 * 24 * 3600)
630+
} else {
631+
false
632+
};
633+
634+
if !self.member_timestamps.is_empty() && !chat_memberlist_is_stale {
625635
headers.push(
626636
Header::new_with_value(
627637
"Chat-Group-Member-Timestamps".into(),

src/param.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ pub enum Param {
183183
GroupNameTimestamp = b'g',
184184

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

190188
/// For Webxdc Message Instances: Current document name

src/receive_imf.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2395,6 +2395,14 @@ async fn apply_group_changes(
23952395
send_event_chat_modified = true;
23962396
}
23972397
}
2398+
2399+
chat_id
2400+
.update_timestamp(
2401+
context,
2402+
Param::MemberListTimestamp,
2403+
mime_parser.timestamp_sent,
2404+
)
2405+
.await?;
23982406
}
23992407

24002408
if let Some(added_id) = added_id {

0 commit comments

Comments
 (0)