From 63f5be69359dd34bf52bea1205d0639d5d960fc5 Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Fri, 13 Mar 2026 14:42:17 +0100 Subject: [PATCH] feat(sync): Allow setting a custom Sliding Sync connection ID and timeline limit on `RoomListService` Signed-off-by: Johannes Marbach --- bindings/matrix-sdk-ffi/CHANGELOG.md | 2 + bindings/matrix-sdk-ffi/src/sync_service.rs | 22 ++++++++ crates/matrix-sdk-ui/CHANGELOG.md | 2 + .../src/room_list_service/mod.rs | 27 +++++++--- crates/matrix-sdk-ui/src/sync_service.rs | 52 +++++++++++++++++-- 5 files changed, 95 insertions(+), 10 deletions(-) diff --git a/bindings/matrix-sdk-ffi/CHANGELOG.md b/bindings/matrix-sdk-ffi/CHANGELOG.md index e79a67f29..a95619a1d 100644 --- a/bindings/matrix-sdk-ffi/CHANGELOG.md +++ b/bindings/matrix-sdk-ffi/CHANGELOG.md @@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file. ### Bug Fixes - Add `Client::set_avatar_url` to manually set the avatar URL of the user to a provided MXC one. +- Allow setting a custom Sliding Sync connection ID and timeline limit on `RoomListService`. + ([#6289](https://github.com/matrix-org/matrix-rust-sdk/pull/6289)) - Fix devices on Android 11 crashing because the SDK could not be initialized using `libloading` to get a reference to the JVM. Replaced `libloading` with `jvm-getter`, which works like a compatibility layer. ([#6370](https://github.com/matrix-org/matrix-rust-sdk/pull/6370)) diff --git a/bindings/matrix-sdk-ffi/src/sync_service.rs b/bindings/matrix-sdk-ffi/src/sync_service.rs index 2acc89561..8cb3bc0d7 100644 --- a/bindings/matrix-sdk-ffi/src/sync_service.rs +++ b/bindings/matrix-sdk-ffi/src/sync_service.rs @@ -128,6 +128,28 @@ impl SyncServiceBuilder { Arc::new(Self { builder, ..this }) } + /// Set a custom Sliding Sync connection ID for the room list service. + /// + /// By default [`matrix_sdk_ui::room_list_service::DEFAULT_CONNECTION_ID`] + /// is used. Set a different value for secondary processes such as iOS + /// Share Extensions that are not meant to reuse the main app's + /// connection. + pub fn with_room_list_connection_id(self: Arc, connection_id: String) -> Arc { + let this = unwrap_or_clone_arc(self); + let builder = this.builder.with_room_list_conn_id(connection_id); + Arc::new(Self { builder, ..this }) + } + + /// Set a custom timeline limit for the room list service. + /// + /// When set, overrides the default timeline limit of + /// [`matrix_sdk_ui::room_list_service::DEFAULT_LIST_TIMELINE_LIMIT`]. + pub fn with_room_list_timeline_limit(self: Arc, limit: u32) -> Arc { + let this = unwrap_or_clone_arc(self); + let builder = this.builder.with_room_list_timeline_limit(limit); + Arc::new(Self { builder, ..this }) + } + pub async fn finish(self: Arc) -> Result, ClientError> { let this = unwrap_or_clone_arc(self); Ok(Arc::new(SyncService { diff --git a/crates/matrix-sdk-ui/CHANGELOG.md b/crates/matrix-sdk-ui/CHANGELOG.md index b9696d507..fe47f07db 100644 --- a/crates/matrix-sdk-ui/CHANGELOG.md +++ b/crates/matrix-sdk-ui/CHANGELOG.md @@ -12,6 +12,8 @@ All notable changes to this project will be documented in this file. `Room::latest_event()`, so room summaries still show the last live location sharing session after it ends. ([#6437](https://github.com/matrix-org/matrix-rust-sdk/pull/6437)) +- Allow setting a custom Sliding Sync connection ID and timeline limit on `RoomListService`. + ([#6289](https://github.com/matrix-org/matrix-rust-sdk/pull/6289)) - Don't show a "sent in clear" shield on live location timeline items in encrypted rooms, since `beacon_info` is a state event that cannot be encrypted by design. diff --git a/crates/matrix-sdk-ui/src/room_list_service/mod.rs b/crates/matrix-sdk-ui/src/room_list_service/mod.rs index 7cd981da8..ed882e3c2 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/mod.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/mod.rs @@ -107,6 +107,12 @@ const DEFAULT_REQUIRED_STATE: &[(StateEventType, &str)] = &[ const DEFAULT_ROOM_SUBSCRIPTION_EXTRA_REQUIRED_STATE: &[(StateEventType, &str)] = &[(StateEventType::RoomPinnedEvents, "")]; +/// The default Sliding Sync connection ID for the room list service. +pub(crate) const DEFAULT_CONNECTION_ID: &str = "room-list"; + +/// The default timeline limit for the room list service. +pub(crate) const DEFAULT_LIST_TIMELINE_LIMIT: u32 = 1; + /// The default `timeline_limit` value when used with room subscriptions. const DEFAULT_ROOM_SUBSCRIPTION_TIMELINE_LIMIT: u32 = 20; @@ -135,16 +141,25 @@ impl RoomListService { /// to create one in this case using /// [`EncryptionSyncService`][crate::encryption_sync_service::EncryptionSyncService]. pub async fn new(client: Client) -> Result { - Self::new_with_share_pos(client, true).await + Self::new_with(client, true, DEFAULT_CONNECTION_ID, DEFAULT_LIST_TIMELINE_LIMIT).await } - /// Like [`RoomListService::new`] but with a flag to turn the - /// [`SlidingSyncBuilder::share_pos`] on and off. + /// Like [`RoomListService::new`] but with additional configuration options. + /// + /// - `share_pos`: toggles [`SlidingSyncBuilder::share_pos`] for + /// cross-process position sharing. + /// - `connection_id`: the Sliding Sync connection ID + /// - `timeline_limit`: the timeline limit /// /// [`SlidingSyncBuilder::share_pos`]: matrix_sdk::sliding_sync::SlidingSyncBuilder::share_pos - pub async fn new_with_share_pos(client: Client, share_pos: bool) -> Result { + pub async fn new_with( + client: Client, + share_pos: bool, + connection_id: &str, + timeline_limit: u32, + ) -> Result { let mut builder = client - .sliding_sync("room-list") + .sliding_sync(connection_id) .map_err(Error::SlidingSync)? .with_account_data_extension( assign!(http::request::AccountData::default(), { enabled: Some(true) }), @@ -202,7 +217,7 @@ impl RoomListService { SlidingSyncMode::new_selective() .add_range(ALL_ROOMS_DEFAULT_SELECTIVE_RANGE), ) - .timeline_limit(1) + .timeline_limit(timeline_limit) .required_state( DEFAULT_REQUIRED_STATE .iter() diff --git a/crates/matrix-sdk-ui/src/sync_service.rs b/crates/matrix-sdk-ui/src/sync_service.rs index 4c64ed355..971fb6db6 100644 --- a/crates/matrix-sdk-ui/src/sync_service.rs +++ b/crates/matrix-sdk-ui/src/sync_service.rs @@ -47,7 +47,9 @@ use tracing::{Instrument, Level, Span, error, info, instrument, trace, warn}; use crate::{ encryption_sync_service::{self, EncryptionSyncPermit, EncryptionSyncService}, - room_list_service::{self, RoomListService}, + room_list_service::{ + self, DEFAULT_CONNECTION_ID, DEFAULT_LIST_TIMELINE_LIMIT, RoomListService, + }, }; /// Current state of the application. @@ -773,6 +775,16 @@ pub struct SyncServiceBuilder { /// [`SlidingSyncBuilder::share_pos`]: matrix_sdk::sliding_sync::SlidingSyncBuilder::share_pos with_share_pos: bool, + /// Custom connection ID for the room list service. + /// Defaults to [`room_list_service::DEFAULT_CONNECTION_ID`]. Use a + /// different value for secondary processes such as iOS share extensions + /// that are not meant to reuse the main app's connection. + room_list_conn_id: String, + + /// Custom timeline limit for the room list service. Defaults to + /// [`room_list_service::DEFAULT_LIST_TIMELINE_LIMIT`]. + room_list_timeline_limit: u32, + /// The parent tracing span to use for the tasks within this service. /// /// Normally this will be [`Span::none`], but it may be useful to assign a @@ -783,7 +795,14 @@ pub struct SyncServiceBuilder { impl SyncServiceBuilder { fn new(client: Client) -> Self { - Self { client, with_offline_mode: false, with_share_pos: true, parent_span: Span::none() } + Self { + client, + with_offline_mode: false, + with_share_pos: true, + room_list_conn_id: DEFAULT_CONNECTION_ID.to_owned(), + room_list_timeline_limit: DEFAULT_LIST_TIMELINE_LIMIT, + parent_span: Span::none(), + } } /// Enable the "offline" mode for the [`SyncService`]. @@ -803,6 +822,18 @@ impl SyncServiceBuilder { self } + /// Set a custom conn_id for the room list sliding sync connection. + pub fn with_room_list_conn_id(mut self, conn_id: String) -> Self { + self.room_list_conn_id = conn_id; + self + } + + /// Set a custom timeline limit for the room list service. + pub fn with_room_list_timeline_limit(mut self, limit: u32) -> Self { + self.room_list_timeline_limit = limit; + self + } + /// Set the parent tracing span to be used for the tasks within this /// service. pub fn with_parent_span(mut self, parent_span: Span) -> Self { @@ -816,11 +847,24 @@ impl SyncServiceBuilder { /// the background. The resulting [`SyncService`] must be kept alive as long /// as the sliding syncs are supposed to run. pub async fn build(self) -> Result { - let Self { client, with_offline_mode, with_share_pos, parent_span } = self; + let Self { + client, + with_offline_mode, + with_share_pos, + room_list_conn_id, + room_list_timeline_limit, + parent_span, + } = self; let encryption_sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new())); - let room_list = RoomListService::new_with_share_pos(client.clone(), with_share_pos).await?; + let room_list = RoomListService::new_with( + client.clone(), + with_share_pos, + &room_list_conn_id, + room_list_timeline_limit, + ) + .await?; let encryption_sync = Arc::new(EncryptionSyncService::new(client, None).await?);