mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-09 08:27:32 -04:00
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.
This commit is contained in:
@@ -119,6 +119,12 @@ impl SyncServiceBuilder {
|
||||
Arc::new(Self { builder, ..this })
|
||||
}
|
||||
|
||||
pub fn with_share_pos(self: Arc<Self>, enable: bool) -> Arc<Self> {
|
||||
let this = unwrap_or_clone_arc(self);
|
||||
let builder = this.builder.with_share_pos(enable);
|
||||
Arc::new(Self { builder, ..this })
|
||||
}
|
||||
|
||||
pub async fn finish(self: Arc<Self>) -> Result<Arc<SyncService>, ClientError> {
|
||||
let this = unwrap_or_clone_arc(self);
|
||||
Ok(Arc::new(SyncService {
|
||||
|
||||
@@ -131,7 +131,15 @@ impl RoomListService {
|
||||
/// to create one in this case using
|
||||
/// [`EncryptionSyncService`][crate::encryption_sync_service::EncryptionSyncService].
|
||||
pub async fn new(client: Client) -> Result<Self, Error> {
|
||||
let builder = client
|
||||
Self::new_with_share_pos(client, true).await
|
||||
}
|
||||
|
||||
/// Like [`RoomListService::new`] but with a flag to turn the
|
||||
/// [`SlidingSyncBuilder::share_pos`] on and off.
|
||||
///
|
||||
/// [`SlidingSyncBuilder::share_pos`]: matrix_sdk::sliding_sync::SlidingSyncBuilder::share_pos
|
||||
pub async fn new_with_share_pos(client: Client, share_pos: bool) -> Result<Self, Error> {
|
||||
let mut builder = client
|
||||
.sliding_sync("room-list")
|
||||
.map_err(Error::SlidingSync)?
|
||||
.with_account_data_extension(
|
||||
@@ -143,9 +151,12 @@ impl RoomListService {
|
||||
}))
|
||||
.with_typing_extension(assign!(http::request::Typing::default(), {
|
||||
enabled: Some(true),
|
||||
}))
|
||||
}));
|
||||
|
||||
if share_pos {
|
||||
// We don't deal with encryption device messages here so this is safe
|
||||
.share_pos();
|
||||
builder = builder.share_pos();
|
||||
}
|
||||
|
||||
let sliding_sync = builder
|
||||
.add_cached_list(
|
||||
|
||||
@@ -763,6 +763,11 @@ pub struct SyncServiceBuilder {
|
||||
/// The offline mode is described in the [`State::Offline`] enum variant.
|
||||
with_offline_mode: bool,
|
||||
|
||||
/// Whether to turn [`SlidingSyncBuilder::share_pos`] on or off.
|
||||
///
|
||||
/// [`SlidingSyncBuilder::share_pos`]: matrix_sdk::sliding_sync::SlidingSyncBuilder::share_pos
|
||||
with_share_pos: bool,
|
||||
|
||||
/// 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
|
||||
@@ -777,6 +782,7 @@ impl SyncServiceBuilder {
|
||||
client,
|
||||
with_cross_process_lock: false,
|
||||
with_offline_mode: false,
|
||||
with_share_pos: true,
|
||||
parent_span: Span::none(),
|
||||
}
|
||||
}
|
||||
@@ -805,6 +811,14 @@ impl SyncServiceBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether to turn [`SlidingSyncBuilder::share_pos`] on or off.
|
||||
///
|
||||
/// [`SlidingSyncBuilder::share_pos`]: matrix_sdk::sliding_sync::SlidingSyncBuilder::share_pos
|
||||
pub fn with_share_pos(mut self, enable: bool) -> Self {
|
||||
self.with_share_pos = enable;
|
||||
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 {
|
||||
@@ -818,11 +832,17 @@ 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<SyncService, Error> {
|
||||
let Self { client, with_cross_process_lock, with_offline_mode, parent_span } = self;
|
||||
let Self {
|
||||
client,
|
||||
with_cross_process_lock,
|
||||
with_offline_mode,
|
||||
with_share_pos,
|
||||
parent_span,
|
||||
} = self;
|
||||
|
||||
let encryption_sync_permit = Arc::new(AsyncMutex::new(EncryptionSyncPermit::new()));
|
||||
|
||||
let room_list = RoomListService::new(client.clone()).await?;
|
||||
let room_list = RoomListService::new_with_share_pos(client.clone(), with_share_pos).await?;
|
||||
|
||||
let encryption_sync = Arc::new(
|
||||
EncryptionSyncService::new(client, None, WithLocking::from(with_cross_process_lock))
|
||||
|
||||
Reference in New Issue
Block a user