diff --git a/bindings/matrix-sdk-ffi/src/sliding_sync.rs b/bindings/matrix-sdk-ffi/src/sliding_sync.rs index 2a191c8dc..1ae7a0cbc 100644 --- a/bindings/matrix-sdk-ffi/src/sliding_sync.rs +++ b/bindings/matrix-sdk-ffi/src/sliding_sync.rs @@ -871,6 +871,14 @@ impl SlidingSyncBuilder { Arc::new(builder) } + pub fn bump_event_types(self: Arc, bump_event_types: Vec) -> Arc { + let mut builder = unwrap_or_clone_arc(self); + builder.inner = builder.inner.bump_event_types( + bump_event_types.into_iter().map(Into::into).collect::>().as_slice(), + ); + Arc::new(builder) + } + pub fn build(self: Arc) -> Result, ClientError> { let builder = unwrap_or_clone_arc(self); RUNTIME.block_on(async move { diff --git a/crates/matrix-sdk/src/sliding_sync/builder.rs b/crates/matrix-sdk/src/sliding_sync/builder.rs index 0eea4760e..558a762aa 100644 --- a/crates/matrix-sdk/src/sliding_sync/builder.rs +++ b/crates/matrix-sdk/src/sliding_sync/builder.rs @@ -10,7 +10,9 @@ use ruma::{ self, AccountDataConfig, E2EEConfig, ExtensionsConfig, ReceiptsConfig, ToDeviceConfig, TypingConfig, }, - assign, OwnedRoomId, + assign, + events::TimelineEventType, + OwnedRoomId, }; use url::Url; @@ -30,6 +32,7 @@ pub struct SlidingSyncBuilder { homeserver: Option, client: Option, lists: BTreeMap, + bump_event_types: Vec, extensions: Option, subscriptions: BTreeMap, } @@ -41,6 +44,7 @@ impl SlidingSyncBuilder { homeserver: None, client: None, lists: BTreeMap::new(), + bump_event_types: Vec::new(), extensions: None, subscriptions: BTreeMap::new(), } @@ -189,6 +193,17 @@ impl SlidingSyncBuilder { self } + /// Allowlist of event types which should be considered recent activity + /// when sorting `by_recency`. By omitting event types, clients can ensure + /// that uninteresting events (e.g. a profile rename) do not cause a + /// room to jump to the top of its list(s). Empty or + /// omitted `bump_event_types` have no effect: all events in a room will + /// be considered recent activity. + pub fn bump_event_types(mut self, bump_event_types: &[TimelineEventType]) -> Self { + self.bump_event_types = bump_event_types.to_vec(); + self + } + /// Build the Sliding Sync. /// /// If `self.storage_key` is `Some(_)`, load the cached data from cold @@ -222,6 +237,7 @@ impl SlidingSyncBuilder { lists, rooms, + bump_event_types: self.bump_event_types, extensions: Mutex::new(self.extensions), reset_counter: Default::default(), diff --git a/crates/matrix-sdk/src/sliding_sync/mod.rs b/crates/matrix-sdk/src/sliding_sync/mod.rs index 3cc6b1794..2e4ff197c 100644 --- a/crates/matrix-sdk/src/sliding_sync/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/mod.rs @@ -49,7 +49,9 @@ use ruma::{ self, AccountDataConfig, E2EEConfig, ExtensionsConfig, ToDeviceConfig, }, }, - assign, OwnedRoomId, RoomId, + assign, + events::TimelineEventType, + OwnedRoomId, RoomId, }; use serde::{Deserialize, Serialize}; use tokio::{spawn, sync::Mutex as AsyncMutex}; @@ -100,13 +102,17 @@ pub(super) struct SlidingSyncInner { /// The rooms details rooms: StdRwLock>, + /// The `bump_event_types` field. See + /// [`SlidingSyncBuilder::bump_event_types`] to learn more. + bump_event_types: Vec, + subscriptions: StdRwLock>, unsubscribe: StdRwLock>, /// Number of times a Sliding Session session has been reset. reset_counter: AtomicU8, - /// the intended state of the extensions being supplied to sliding /sync + /// The intended state of the extensions being supplied to sliding /sync /// calls. May contain the latest next_batch for to_devices, etc. extensions: Mutex>, } @@ -411,6 +417,7 @@ impl SlidingSync { txn_id: Some(stream_id.to_owned()), timeout: Some(timeout), lists: requests_lists, + bump_event_types: self.inner.bump_event_types.clone(), room_subscriptions, unsubscribe_rooms, extensions,