Skip to content

Commit 69520be

Browse files
committed
feat(sync): Allow setting a custom Sliding Sync connection ID and timeline limit on RoomListService
Signed-off-by: Johannes Marbach <n0-0ne+github@mailbox.org>
1 parent acda2e8 commit 69520be

File tree

5 files changed

+98
-10
lines changed

5 files changed

+98
-10
lines changed

bindings/matrix-sdk-ffi/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.
88

99
### Bug Fixes
1010

11+
- Allow setting a custom Sliding Sync connection ID and timeline limit on `RoomListService`.
12+
([#6289](https://github.com/matrix-org/matrix-rust-sdk/pull/?))
1113
- [**breaking**] `OtherState` properly supports redacted events that still have fields in the
1214
content. The following fields are no longer optional:
1315
- `federate` in `OtherState::RoomCreate`.

bindings/matrix-sdk-ffi/src/sync_service.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,26 @@ impl SyncServiceBuilder {
128128
Arc::new(Self { builder, ..this })
129129
}
130130

131+
/// Set a custom Sliding Sync connection ID for the room list service.
132+
///
133+
/// By default "room-list" is used. Set a different value for secondary
134+
/// processes such as iOS Share Extensions that are not meant to reuse the
135+
/// main app's connection.
136+
pub fn with_room_list_conn_id(self: Arc<Self>, conn_id: String) -> Arc<Self> {
137+
let this = unwrap_or_clone_arc(self);
138+
let builder = this.builder.with_room_list_conn_id(conn_id);
139+
Arc::new(Self { builder, ..this })
140+
}
141+
142+
/// Set a custom timeline limit for the room list service.
143+
///
144+
/// When set, overrides the default timeline limit of 0.
145+
pub fn with_room_list_timeline_limit(self: Arc<Self>, limit: u32) -> Arc<Self> {
146+
let this = unwrap_or_clone_arc(self);
147+
let builder = this.builder.with_room_list_timeline_limit(limit);
148+
Arc::new(Self { builder, ..this })
149+
}
150+
131151
pub async fn finish(self: Arc<Self>) -> Result<Arc<SyncService>, ClientError> {
132152
let this = unwrap_or_clone_arc(self);
133153
Ok(Arc::new(SyncService {

crates/matrix-sdk-ui/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.
88

99
### Bug Fixes
1010

11+
- Allow setting a custom Sliding Sync connection ID and timeline limit on `RoomListService`.
12+
([#6289](https://github.com/matrix-org/matrix-rust-sdk/pull/?))
1113
- Include secondary relations when re-initializing a threaded timeline after a lag.
1214
([#6209](https://github.com/matrix-org/matrix-rust-sdk/pull/6209))
1315
- Ensure that the display name of a `Room` in a `NotificationStatus` coming

crates/matrix-sdk-ui/src/room_list_service/mod.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ const DEFAULT_REQUIRED_STATE: &[(StateEventType, &str)] = &[
105105
const DEFAULT_ROOM_SUBSCRIPTION_EXTRA_REQUIRED_STATE: &[(StateEventType, &str)] =
106106
&[(StateEventType::RoomPinnedEvents, "")];
107107

108+
/// The default Sliding Sync connection ID for the room list service.
109+
pub(crate) const DEFAULT_ROOM_LIST_CONN_ID: &str = "room-list";
110+
111+
/// The default timeline limit for the room list service.
112+
pub(crate) const DEFAULT_ROOM_LIST_TIMELINE_LIMIT: u32 = 1;
113+
108114
/// The default `timeline_limit` value when used with room subscriptions.
109115
const DEFAULT_ROOM_SUBSCRIPTION_TIMELINE_LIMIT: u32 = 20;
110116

@@ -133,16 +139,31 @@ impl RoomListService {
133139
/// to create one in this case using
134140
/// [`EncryptionSyncService`][crate::encryption_sync_service::EncryptionSyncService].
135141
pub async fn new(client: Client) -> Result<Self, Error> {
136-
Self::new_with_share_pos(client, true).await
142+
Self::new_with_share_pos(
143+
client,
144+
true,
145+
DEFAULT_ROOM_LIST_CONN_ID,
146+
DEFAULT_ROOM_LIST_TIMELINE_LIMIT,
147+
)
148+
.await
137149
}
138150

139-
/// Like [`RoomListService::new`] but with a flag to turn the
140-
/// [`SlidingSyncBuilder::share_pos`] on and off.
151+
/// Like [`RoomListService::new`] but with additional configuration options.
152+
///
153+
/// - `share_pos`: en- or disables [`SlidingSyncBuilder::share_pos`] for
154+
/// cross-process position sharing.
155+
/// - `conn_id`: the Sliding Sync connection ID
156+
/// - `timeline_limit`: the timeline limit
141157
///
142158
/// [`SlidingSyncBuilder::share_pos`]: matrix_sdk::sliding_sync::SlidingSyncBuilder::share_pos
143-
pub async fn new_with_share_pos(client: Client, share_pos: bool) -> Result<Self, Error> {
159+
pub async fn new_with_share_pos(
160+
client: Client,
161+
share_pos: bool,
162+
conn_id: &str,
163+
timeline_limit: u32,
164+
) -> Result<Self, Error> {
144165
let mut builder = client
145-
.sliding_sync("room-list")
166+
.sliding_sync(conn_id)
146167
.map_err(Error::SlidingSync)?
147168
.with_account_data_extension(
148169
assign!(http::request::AccountData::default(), { enabled: Some(true) }),
@@ -200,7 +221,7 @@ impl RoomListService {
200221
SlidingSyncMode::new_selective()
201222
.add_range(ALL_ROOMS_DEFAULT_SELECTIVE_RANGE),
202223
)
203-
.timeline_limit(1)
224+
.timeline_limit(timeline_limit)
204225
.required_state(
205226
DEFAULT_REQUIRED_STATE
206227
.iter()

crates/matrix-sdk-ui/src/sync_service.rs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ use tracing::{Instrument, Level, Span, error, info, instrument, trace, warn};
4747

4848
use crate::{
4949
encryption_sync_service::{self, EncryptionSyncPermit, EncryptionSyncService},
50-
room_list_service::{self, RoomListService},
50+
room_list_service::{
51+
self, DEFAULT_ROOM_LIST_CONN_ID, DEFAULT_ROOM_LIST_TIMELINE_LIMIT, RoomListService,
52+
},
5153
};
5254

5355
/// Current state of the application.
@@ -774,6 +776,15 @@ pub struct SyncServiceBuilder {
774776
/// [`SlidingSyncBuilder::share_pos`]: matrix_sdk::sliding_sync::SlidingSyncBuilder::share_pos
775777
with_share_pos: bool,
776778

779+
/// Custom connection ID for the room list service.
780+
/// Defaults to "room-list". Use a different value for
781+
/// secondary processes such as iOS share extensions that are not
782+
/// meant to reuse the main app's connection.
783+
room_list_conn_id: String,
784+
785+
/// Custom timeline limit for the room list service. Defaults to 1.
786+
room_list_timeline_limit: u32,
787+
777788
/// The parent tracing span to use for the tasks within this service.
778789
///
779790
/// Normally this will be [`Span::none`], but it may be useful to assign a
@@ -784,7 +795,14 @@ pub struct SyncServiceBuilder {
784795

785796
impl SyncServiceBuilder {
786797
fn new(client: Client) -> Self {
787-
Self { client, with_offline_mode: false, with_share_pos: true, parent_span: Span::none() }
798+
Self {
799+
client,
800+
with_offline_mode: false,
801+
with_share_pos: true,
802+
room_list_conn_id: DEFAULT_ROOM_LIST_CONN_ID.to_owned(),
803+
room_list_timeline_limit: DEFAULT_ROOM_LIST_TIMELINE_LIMIT,
804+
parent_span: Span::none(),
805+
}
788806
}
789807

790808
/// Enable the "offline" mode for the [`SyncService`].
@@ -804,6 +822,18 @@ impl SyncServiceBuilder {
804822
self
805823
}
806824

825+
/// Set a custom conn_id for the room list sliding sync connection.
826+
pub fn with_room_list_conn_id(mut self, conn_id: String) -> Self {
827+
self.room_list_conn_id = conn_id;
828+
self
829+
}
830+
831+
/// Set a custom timeline limit for the room list service.
832+
pub fn with_room_list_timeline_limit(mut self, limit: u32) -> Self {
833+
self.room_list_timeline_limit = limit;
834+
self
835+
}
836+
807837
/// Set the parent tracing span to be used for the tasks within this
808838
/// service.
809839
pub fn with_parent_span(mut self, parent_span: Span) -> Self {
@@ -817,11 +847,24 @@ impl SyncServiceBuilder {
817847
/// the background. The resulting [`SyncService`] must be kept alive as long
818848
/// as the sliding syncs are supposed to run.
819849
pub async fn build(self) -> Result<SyncService, Error> {
820-
let Self { client, with_offline_mode, with_share_pos, parent_span } = self;
850+
let Self {
851+
client,
852+
with_offline_mode,
853+
with_share_pos,
854+
room_list_conn_id,
855+
room_list_timeline_limit,
856+
parent_span,
857+
} = self;
821858

822859
let encryption_sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new()));
823860

824-
let room_list = RoomListService::new_with_share_pos(client.clone(), with_share_pos).await?;
861+
let room_list = RoomListService::new_with_share_pos(
862+
client.clone(),
863+
with_share_pos,
864+
&room_list_conn_id,
865+
room_list_timeline_limit,
866+
)
867+
.await?;
825868

826869
let encryption_sync = Arc::new(EncryptionSyncService::new(client, None).await?);
827870

0 commit comments

Comments
 (0)