From 1c2e7d8c0d582d52115718ff6c3eee5826836bfb Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 24 Apr 2023 09:56:55 +0200 Subject: [PATCH 1/3] chore: Update `Cargo.lock`. --- Cargo.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.lock b/Cargo.lock index b75ae6595..f35f240b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2698,6 +2698,7 @@ name = "matrix-sdk-crypto-ffi" version = "0.1.0" dependencies = [ "anyhow", + "assert_matches", "base64 0.21.0", "futures-util", "hmac", From 7b2b3fa78f71b7b767e4132cca19452d056138d7 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 24 Apr 2023 09:57:22 +0200 Subject: [PATCH 2/3] feat(sdk): Add support for `bump_event_types` in `SlidingSync`. The `SlidingSyncBuilder` now has a new method: `bump_event_types`, to configure the `bump_event_types` HTTP request parameter. This value is passed to `SlidingSync`, which is used to build the `SlidingSync` request. --- crates/matrix-sdk/src/sliding_sync/builder.rs | 18 +++++++++++++++++- crates/matrix-sdk/src/sliding_sync/mod.rs | 11 +++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) 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 038996a39..97b3e0738 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, From be7b79b4e5d010666ecc6c8fe89fe0493149bbb5 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 24 Apr 2023 09:58:30 +0200 Subject: [PATCH 3/3] feat(ffi): Add binding for `SlidingSyncBuilder::bump_event_types`. This patch adds a new binding on `SlidingSyncBuilder` to `matrix_sdk::SlidingSyncBuilder::bump_event_types`. --- bindings/matrix-sdk-ffi/src/sliding_sync.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bindings/matrix-sdk-ffi/src/sliding_sync.rs b/bindings/matrix-sdk-ffi/src/sliding_sync.rs index 12d9cc059..09b0dbc6a 100644 --- a/bindings/matrix-sdk-ffi/src/sliding_sync.rs +++ b/bindings/matrix-sdk-ffi/src/sliding_sync.rs @@ -881,6 +881,14 @@ impl SlidingSyncBuilder { builder.inner = builder.inner.with_all_extensions(); 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) + } } #[uniffi::export]