From 919fea9b97532e16e416a9e938fdb48c55c2c02e Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Tue, 13 Oct 2026 13:48:54 +0200 Subject: [PATCH] fix: Index remote events by origin_server_ts --- src/service/migrations.rs | 3 ++- src/service/rooms/timeline/append.rs | 14 +++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/service/migrations.rs b/src/service/migrations.rs index 53dc5567e..ac4825d8d 100644 --- a/src/service/migrations.rs +++ b/src/service/migrations.rs @@ -180,7 +180,8 @@ migration!(stringify!($name) => $name) // This is backwards compatible because old versions never read the // account data entries it removes. migration!(remove_replaced_account_data), - // This is backwards compatible because old versions ignore the `roomts_pduid` keyspace. + // This is backwards compatible because old versions ignore the + // `roomts_pduid` keyspace. Migration(rooms::timeline::TIMESTAMP_INDEX_MIGRATION, |services| { Box::pin(async { let global = &services.db["global"]; diff --git a/src/service/rooms/timeline/append.rs b/src/service/rooms/timeline/append.rs index 8304ad055..887dca516 100644 --- a/src/service/rooms/timeline/append.rs +++ b/src/service/rooms/timeline/append.rs @@ -23,8 +23,8 @@ use conduwuit_core::{ }; use futures::{FutureExt, StreamExt, TryFutureExt, pin_mut}; use ruma::{ - CanonicalJsonObject, CanonicalJsonValue, MilliSecondsSinceUnixEpoch, OwnedEventId, - OwnedRoomId, OwnedServerName, RoomId, RoomVersionId, ServerName, UserId, + CanonicalJsonObject, CanonicalJsonValue, OwnedEventId, OwnedRoomId, OwnedServerName, RoomId, + RoomVersionId, ServerName, UserId, events::{ AnySyncTimelineEvent, GlobalAccountDataEventType, TimelineEventType, push_rules::PushRulesEvent, @@ -347,17 +347,9 @@ impl super::Service { let count2 = PduCount::Normal(self.services.globals.next_count().unwrap()); let pdu_id: RawPduId = PduId { shortroomid, shorteventid: count2 }.into(); - // Remote timestamps are untrusted, so index remote events by when we - // received them - let index_ts = if self.services.globals.user_is_local(pdu.sender()) { - pdu.origin_server_ts() - } else { - MilliSecondsSinceUnixEpoch::now() - }; - // Insert pdu self.db - .append_pdu(&pdu_id, pdu, room_id, &pdu_json, count2, index_ts) + .append_pdu(&pdu_id, pdu, room_id, &pdu_json, count2, pdu.origin_server_ts()) .await; self.progress_extremities(pdu) .await