syncv3: include latest timestamps, calculated from a default set of types

List borrowed from synapse
This commit is contained in:
morguldir 2024-08-24 14:52:48 +02:00
parent f4c8b77377
commit 29a6065bae
No known key found for this signature in database
GPG key ID: 5A6025D4F6E7A8A3
2 changed files with 22 additions and 10 deletions

View file

@ -336,6 +336,8 @@ features = [
"unstable-msc3026",
"unstable-msc3061",
"unstable-msc3266",
"unstable-msc3381", # polls
"unstable-msc3489", # beacon / live location
"unstable-msc3575",
"unstable-msc4121",
"unstable-msc4125",

View file

@ -25,15 +25,9 @@ use ruma::{
DeviceLists, UnreadNotificationsCount,
},
uiaa::UiaaResponse,
},
events::{
presence::PresenceEvent,
room::member::{MembershipState, RoomMemberEventContent},
StateEventType, TimelineEventType,
},
room::RoomType,
serde::Raw,
uint, DeviceId, EventId, OwnedRoomId, OwnedUserId, RoomId, UInt, UserId,
}, events::{
presence::PresenceEvent, room::member::{MembershipState, RoomMemberEventContent}, StateEventType, TimelineEventType
}, room::RoomType, serde::Raw, state_res::Event, uint, DeviceId, EventId, MilliSecondsSinceUnixEpoch, OwnedRoomId, OwnedUserId, RoomId, UInt, UserId
};
use tracing::{Instrument as _, Span};
@ -43,6 +37,14 @@ use crate::{
};
const SINGLE_CONNECTION_SYNC: &str = "single_connection_sync";
const DEFAULT_BUMP_TYPES: &[TimelineEventType] = &[
TimelineEventType::Message,
TimelineEventType::Encrypted,
TimelineEventType::Sticker,
TimelineEventType::CallInvite,
TimelineEventType::PollStart,
TimelineEventType::Beacon,
];
/// # `GET /_matrix/client/r0/sync`
///
@ -1500,6 +1502,14 @@ pub(crate) async fn sync_events_v4_route(
None
};
let mut timestamp: Option<_> = None;
for (_, pdu) in timeline_pdus {
timestamp = Some(MilliSecondsSinceUnixEpoch(pdu.origin_server_ts));
if DEFAULT_BUMP_TYPES.contains(pdu.event_type()) {
break;
}
}
let required_state = required_state_request
.iter()
.map(|state| {
@ -1622,7 +1632,7 @@ pub(crate) async fn sync_events_v4_route(
.unwrap_or_else(|_| uint!(0)),
),
num_live: None, // Count events in timeline greater than global sync counter
timestamp: None,
timestamp,
heroes: Some(heroes),
},
);