Skip to content

Commit fcdb63d

Browse files
committed
feat(ui): Add RoomListService::new_with_share_pos.
This patch adds the new `RoomListService::new_with_share_pos` constructor. It decides whether the `share_pos` feature of sliding sync should be enabled or not. `SyncServiceBuilder` gains a new `with_share_pos` method to configure the way the `RoomListService` is built. The FFI bindings are updated accordingly.
1 parent a095872 commit fcdb63d

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ impl SyncServiceBuilder {
119119
Arc::new(Self { builder, ..this })
120120
}
121121

122+
pub fn with_share_pos(self: Arc<Self>, enable: bool) -> Arc<Self> {
123+
let this = unwrap_or_clone_arc(self);
124+
let builder = this.builder.with_share_pos(enable);
125+
Arc::new(Self { builder, ..this })
126+
}
127+
122128
pub async fn finish(self: Arc<Self>) -> Result<Arc<SyncService>, ClientError> {
123129
let this = unwrap_or_clone_arc(self);
124130
Ok(Arc::new(SyncService {

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,15 @@ impl RoomListService {
131131
/// to create one in this case using
132132
/// [`EncryptionSyncService`][crate::encryption_sync_service::EncryptionSyncService].
133133
pub async fn new(client: Client) -> Result<Self, Error> {
134-
let builder = client
134+
Self::new_with_share_pos(client, true).await
135+
}
136+
137+
/// Like [`RoomListService::new`] but with a flag to turn the
138+
/// [`SlidingSyncBuilder::share_pos`] on and off.
139+
///
140+
/// [`SlidingSyncBuilder::share_pos`]: matrix_sdk::sliding_sync::SlidingSyncBuilder::share_pos
141+
pub async fn new_with_share_pos(client: Client, share_pos: bool) -> Result<Self, Error> {
142+
let mut builder = client
135143
.sliding_sync("room-list")
136144
.map_err(Error::SlidingSync)?
137145
.with_account_data_extension(
@@ -143,9 +151,12 @@ impl RoomListService {
143151
}))
144152
.with_typing_extension(assign!(http::request::Typing::default(), {
145153
enabled: Some(true),
146-
}))
154+
}));
155+
156+
if share_pos {
147157
// We don't deal with encryption device messages here so this is safe
148-
.share_pos();
158+
builder = builder.share_pos();
159+
}
149160

150161
let sliding_sync = builder
151162
.add_cached_list(

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,11 @@ pub struct SyncServiceBuilder {
763763
/// The offline mode is described in the [`State::Offline`] enum variant.
764764
with_offline_mode: bool,
765765

766+
/// Whether to turn [`SlidingSyncBuilder::share_pos`] on or off.
767+
///
768+
/// [`SlidingSyncBuilder::share_pos`]: matrix_sdk::sliding_sync::SlidingSyncBuilder::share_pos
769+
with_share_pos: bool,
770+
766771
/// The parent tracing span to use for the tasks within this service.
767772
///
768773
/// Normally this will be [`Span::none`], but it may be useful to assign a
@@ -777,6 +782,7 @@ impl SyncServiceBuilder {
777782
client,
778783
with_cross_process_lock: false,
779784
with_offline_mode: false,
785+
with_share_pos: true,
780786
parent_span: Span::none(),
781787
}
782788
}
@@ -805,6 +811,14 @@ impl SyncServiceBuilder {
805811
self
806812
}
807813

814+
/// Whether to turn [`SlidingSyncBuilder::share_pos`] on or off.
815+
///
816+
/// [`SlidingSyncBuilder::share_pos`]: matrix_sdk::sliding_sync::SlidingSyncBuilder::share_pos
817+
pub fn with_share_pos(mut self, enable: bool) -> Self {
818+
self.with_share_pos = enable;
819+
self
820+
}
821+
808822
/// Set the parent tracing span to be used for the tasks within this
809823
/// service.
810824
pub fn with_parent_span(mut self, parent_span: Span) -> Self {
@@ -818,11 +832,17 @@ impl SyncServiceBuilder {
818832
/// the background. The resulting [`SyncService`] must be kept alive as long
819833
/// as the sliding syncs are supposed to run.
820834
pub async fn build(self) -> Result<SyncService, Error> {
821-
let Self { client, with_cross_process_lock, with_offline_mode, parent_span } = self;
835+
let Self {
836+
client,
837+
with_cross_process_lock,
838+
with_offline_mode,
839+
with_share_pos,
840+
parent_span,
841+
} = self;
822842

823843
let encryption_sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new()));
824844

825-
let room_list = RoomListService::new(client.clone()).await?;
845+
let room_list = RoomListService::new_with_share_pos(client.clone(), with_share_pos).await?;
826846

827847
let encryption_sync = Arc::new(
828848
EncryptionSyncService::new(client, None, WithLocking::from(with_cross_process_lock))

0 commit comments

Comments
 (0)