diff --git a/bindings/matrix-sdk-ffi/src/sliding_sync.rs b/bindings/matrix-sdk-ffi/src/sliding_sync.rs index ebefb2f85..1c7f04356 100644 --- a/bindings/matrix-sdk-ffi/src/sliding_sync.rs +++ b/bindings/matrix-sdk-ffi/src/sliding_sync.rs @@ -560,6 +560,14 @@ impl SlidingSyncListBuilder { ); 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 trait SlidingSyncListOnceBuilt: Sync + Send { @@ -876,14 +884,6 @@ 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 7b44beeea..9ea561e93 100644 --- a/crates/matrix-sdk/src/sliding_sync/builder.rs +++ b/crates/matrix-sdk/src/sliding_sync/builder.rs @@ -5,7 +5,6 @@ use ruma::{ self, AccountDataConfig, E2EEConfig, ExtensionsConfig, ReceiptsConfig, ToDeviceConfig, TypingConfig, }, - events::TimelineEventType, OwnedRoomId, }; use tokio::sync::broadcast::channel; @@ -27,7 +26,6 @@ pub struct SlidingSyncBuilder { homeserver: Option, client: Client, lists: Vec, - bump_event_types: Vec, extensions: Option, subscriptions: BTreeMap, rooms: BTreeMap, @@ -40,7 +38,6 @@ impl SlidingSyncBuilder { homeserver: None, client, lists: Vec::new(), - bump_event_types: Vec::new(), extensions: None, subscriptions: BTreeMap::new(), rooms: BTreeMap::new(), @@ -205,17 +202,6 @@ 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 @@ -258,7 +244,6 @@ impl SlidingSyncBuilder { lists, rooms, - bump_event_types: self.bump_event_types, extensions: self.extensions.unwrap_or_default(), reset_counter: Default::default(), diff --git a/crates/matrix-sdk/src/sliding_sync/list/builder.rs b/crates/matrix-sdk/src/sliding_sync/list/builder.rs index 3a627823f..1dbdfb7e1 100644 --- a/crates/matrix-sdk/src/sliding_sync/list/builder.rs +++ b/crates/matrix-sdk/src/sliding_sync/list/builder.rs @@ -10,7 +10,11 @@ use std::{ use eyeball::unique::Observable; use eyeball_im::ObservableVector; use imbl::Vector; -use ruma::{api::client::sync::sync_events::v4, events::StateEventType, OwnedRoomId}; +use ruma::{ + api::client::sync::sync_events::v4, + events::{StateEventType, TimelineEventType}, + OwnedRoomId, +}; use tokio::sync::broadcast::Sender; use super::{ @@ -53,6 +57,8 @@ pub struct SlidingSyncListBuilder { reloaded_cached_data: Option, once_built: Arc SlidingSyncList + Send + Sync>>, + + bump_event_types: Vec, } // Print debug values for the builder, except `once_built` which is ignored. @@ -66,6 +72,7 @@ impl fmt::Debug for SlidingSyncListBuilder { .field("filters", &self.filters) .field("timeline_limit", &self.timeline_limit) .field("name", &self.name) + .field("bump_event_types", &self.bump_event_types) .finish_non_exhaustive() } } @@ -85,6 +92,7 @@ impl SlidingSyncListBuilder { reloaded_cached_data: None, cache_policy: SlidingSyncListCachePolicy::Disabled, once_built: Arc::new(Box::new(identity)), + bump_event_types: Vec::new(), } } @@ -166,6 +174,19 @@ impl SlidingSyncListBuilder { } } + /// 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 list. pub(in super::super) fn build( self, @@ -180,6 +201,7 @@ impl SlidingSyncListBuilder { timeline_limit: StdRwLock::new(self.timeline_limit), name: self.name, cache_policy: self.cache_policy, + bump_event_types: self.bump_event_types, // Computed from the builder. request_generator: StdRwLock::new(SlidingSyncListRequestGenerator::new( diff --git a/crates/matrix-sdk/src/sliding_sync/list/mod.rs b/crates/matrix-sdk/src/sliding_sync/list/mod.rs index b429a4fca..8aad9b4f7 100644 --- a/crates/matrix-sdk/src/sliding_sync/list/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/list/mod.rs @@ -18,7 +18,12 @@ pub(super) use frozen::FrozenSlidingSyncList; use futures_core::Stream; pub(super) use request_generator::*; pub use room_list_entry::RoomListEntry; -use ruma::{api::client::sync::sync_events::v4, assign, events::StateEventType, OwnedRoomId}; +use ruma::{ + api::client::sync::sync_events::v4, + assign, + events::{StateEventType, TimelineEventType}, + OwnedRoomId, +}; use serde::{Deserialize, Serialize}; use tokio::sync::broadcast::Sender; use tracing::{instrument, warn}; @@ -251,6 +256,10 @@ pub(super) struct SlidingSyncListInner { /// The Sliding Sync internal channel sender. See /// [`SlidingSyncInner::internal_channel`] to learn more. sliding_sync_internal_channel_sender: Sender, + + /// The `bump_event_types` field. See + /// [`SlidingSyncListBuilder::bump_event_types`] to learn more. + bump_event_types: Vec, } impl SlidingSyncListInner { @@ -314,6 +323,7 @@ impl SlidingSyncListInner { }), sort, filters, + bump_event_types: self.bump_event_types.clone(), }) } diff --git a/crates/matrix-sdk/src/sliding_sync/mod.rs b/crates/matrix-sdk/src/sliding_sync/mod.rs index 7691bed6c..b1a91c73a 100644 --- a/crates/matrix-sdk/src/sliding_sync/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/mod.rs @@ -44,9 +44,7 @@ use ruma::{ error::ErrorKind, sync::sync_events::v4::{self, ExtensionsConfig}, }, - assign, - events::TimelineEventType, - OwnedRoomId, RoomId, + assign, OwnedRoomId, RoomId, }; use serde::{Deserialize, Serialize}; use tokio::{ @@ -99,10 +97,6 @@ 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, - /// Room subscriptions, i.e. rooms that may be out-of-scope of all lists but /// one wants to receive updates. room_subscriptions: StdRwLock>, @@ -418,7 +412,6 @@ impl SlidingSync { delta_token, timeout: Some(timeout), lists: requests_lists, - bump_event_types: self.inner.bump_event_types.clone(), room_subscriptions, unsubscribe_rooms: room_unsubscriptions.iter().cloned().collect(), extensions,