Skip to content

Commit 997393e

Browse files
committed
Deprecate member list timestamp
1 parent bb7f8e9 commit 997393e

File tree

4 files changed

+4
-78
lines changed

4 files changed

+4
-78
lines changed

src/chat.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,15 +1221,6 @@ 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 get_member_list_timestamp(self, context: &Context) -> Result<i64> {
1226-
Ok(self
1227-
.get_param(context)
1228-
.await?
1229-
.get_i64(Param::MemberListTimestamp)
1230-
.unwrap_or_default())
1231-
}
1232-
12331224
async fn parent_query<T, F>(
12341225
self,
12351226
context: &Context,
@@ -3008,18 +2999,6 @@ pub(crate) async fn create_send_msg_jobs(context: &Context, msg: &mut Message) -
30082999
msg.chat_id.set_gossiped_timestamp(context, now).await?;
30093000
}
30103001

3011-
if msg.param.get_cmd() == SystemMessage::MemberRemovedFromGroup {
3012-
// Reject member list synchronisation from older messages. See also
3013-
// `receive_imf::apply_group_changes()`.
3014-
msg.chat_id
3015-
.update_timestamp(
3016-
context,
3017-
Param::MemberListTimestamp,
3018-
now.saturating_add(constants::TIMESTAMP_SENT_TOLERANCE),
3019-
)
3020-
.await?;
3021-
}
3022-
30233002
if rendered_msg.last_added_location_id.is_some() {
30243003
if let Err(err) = location::set_kml_sent_timestamp(context, msg.chat_id, now).await {
30253004
error!(context, "Failed to set kml sent_timestamp: {err:#}.");

src/param.rs

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

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

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

src/receive_imf.rs

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use regex::Regex;
1414
use crate::aheader::EncryptPreference;
1515
use crate::chat::{self, Chat, ChatId, ChatIdBlocked, ProtectionStatus};
1616
use crate::config::Config;
17-
use crate::constants::{self, Blocked, Chattype, ShowEmails, DC_CHAT_ID_TRASH};
17+
use crate::constants::{Blocked, Chattype, ShowEmails, DC_CHAT_ID_TRASH};
1818
use crate::contact::{Contact, ContactId, Origin};
1919
use crate::context::Context;
2020
use crate::debug_logging::maybe_set_logging_xdc_inner;
@@ -929,7 +929,6 @@ async fn add_parts(
929929
from_id,
930930
to_ids,
931931
past_ids,
932-
is_partial_download.is_some(),
933932
&verified_encryption,
934933
)
935934
.await?;
@@ -1200,7 +1199,6 @@ async fn add_parts(
12001199
from_id,
12011200
to_ids,
12021201
past_ids,
1203-
is_partial_download.is_some(),
12041202
&verified_encryption,
12051203
)
12061204
.await?;
@@ -2158,7 +2156,6 @@ async fn apply_group_changes(
21582156
from_id: ContactId,
21592157
to_ids: &[ContactId],
21602158
past_ids: &[ContactId],
2161-
is_partial_download: bool,
21622159
verified_encryption: &VerifiedEncryption,
21632160
) -> Result<(Vec<String>, Option<String>)> {
21642161
if chat_id.is_special() {
@@ -2185,18 +2182,7 @@ async fn apply_group_changes(
21852182

21862183
let mut chat_contacts =
21872184
HashSet::<ContactId>::from_iter(chat::get_chat_contacts(context, chat_id).await?);
2188-
let is_from_in_chat =
2189-
!chat_contacts.contains(&ContactId::SELF) || chat_contacts.contains(&from_id);
2190-
// Reject group membership changes from non-members and old changes.
2191-
let member_list_ts = match !is_partial_download && is_from_in_chat {
2192-
true => Some(chat_id.get_member_list_timestamp(context).await?),
2193-
false => None,
2194-
};
21952185

2196-
let timestamp_sent_tolerance = constants::TIMESTAMP_SENT_TOLERANCE * 2;
2197-
let sync_member_list = member_list_ts
2198-
.filter(|t| *t <= mime_parser.timestamp_sent)
2199-
.is_some();
22002186
// Whether to rebuild the member list from scratch.
22012187
let recreate_member_list = self_added;
22022188

@@ -2342,9 +2328,7 @@ async fn apply_group_changes(
23422328
let mut removed_ids = HashSet::<ContactId>::new();
23432329

23442330
if !recreate_member_list {
2345-
if sync_member_list {
2346-
added_ids = new_members.difference(&chat_contacts).copied().collect();
2347-
} else if let Some(added_id) = added_id {
2331+
if let Some(added_id) = added_id {
23482332
added_ids.insert(added_id);
23492333
}
23502334
new_members.clone_from(&chat_contacts);
@@ -2423,17 +2407,6 @@ async fn apply_group_changes(
24232407
chat_contacts = new_members;
24242408
send_event_chat_modified = true;
24252409
}
2426-
if sync_member_list {
2427-
let mut ts = mime_parser.timestamp_sent;
2428-
if recreate_member_list {
2429-
// Reject all older membership changes. See `allow_member_list_changes` to know how
2430-
// this works.
2431-
ts += timestamp_sent_tolerance;
2432-
}
2433-
chat_id
2434-
.update_timestamp(context, Param::MemberListTimestamp, ts)
2435-
.await?;
2436-
}
24372410
}
24382411

24392412
if let Some(avatar_action) = &mime_parser.group_avatar {

src/receive_imf/tests.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4782,13 +4782,6 @@ async fn test_partial_group_consistency() -> Result<()> {
47824782
let contacts = get_chat_contacts(&bob, bob_chat_id).await?;
47834783
assert_eq!(contacts.len(), 2);
47844784

4785-
// Get initial timestamp.
4786-
let timestamp = bob_chat_id
4787-
.get_param(&bob)
4788-
.await?
4789-
.get_i64(Param::MemberListTimestamp)
4790-
.unwrap();
4791-
47924785
// Bob receives partial message.
47934786
let msg_id = receive_imf_from_inbox(
47944787
&bob,
@@ -4809,15 +4802,9 @@ Chat-Group-Member-Added: charlie@example.com",
48094802
.context("no received message")?;
48104803

48114804
let msg = Message::load_from_db(&bob, msg_id.msg_ids[0]).await?;
4812-
let timestamp2 = bob_chat_id
4813-
.get_param(&bob)
4814-
.await?
4815-
.get_i64(Param::MemberListTimestamp)
4816-
.unwrap();
48174805

48184806
// Partial download does not change the member list.
48194807
assert_eq!(msg.download_state, DownloadState::Available);
4820-
assert_eq!(timestamp, timestamp2);
48214808
assert_eq!(get_chat_contacts(&bob, bob_chat_id).await?, contacts);
48224809

48234810
// Alice sends normal message to bob, adding fiona.
@@ -4830,15 +4817,6 @@ Chat-Group-Member-Added: charlie@example.com",
48304817

48314818
bob.recv_msg(&alice.pop_sent_msg().await).await;
48324819

4833-
let timestamp3 = bob_chat_id
4834-
.get_param(&bob)
4835-
.await?
4836-
.get_i64(Param::MemberListTimestamp)
4837-
.unwrap();
4838-
4839-
// Receiving a message after a partial download recreates the member list because we treat
4840-
// such messages as if we have not seen them.
4841-
assert_ne!(timestamp, timestamp3);
48424820
let contacts = get_chat_contacts(&bob, bob_chat_id).await?;
48434821
assert_eq!(contacts.len(), 3);
48444822

@@ -4862,15 +4840,9 @@ Chat-Group-Member-Added: charlie@example.com",
48624840
.context("no received message")?;
48634841

48644842
let msg = Message::load_from_db(&bob, msg_id.msg_ids[0]).await?;
4865-
let timestamp4 = bob_chat_id
4866-
.get_param(&bob)
4867-
.await?
4868-
.get_i64(Param::MemberListTimestamp)
4869-
.unwrap();
48704843

48714844
// After full download, the old message should not change group state.
48724845
assert_eq!(msg.download_state, DownloadState::Done);
4873-
assert_eq!(timestamp3, timestamp4);
48744846
assert_eq!(get_chat_contacts(&bob, bob_chat_id).await?, contacts);
48754847

48764848
Ok(())

0 commit comments

Comments
 (0)