From e92841d6bc66a3f5022f8d0be9d4c8d4649b4f2f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Mon, 20 Feb 2023 12:30:31 +0100 Subject: [PATCH] refactor(sdk): Inline Mutable type aliases --- crates/matrix-sdk/src/sliding_sync/mod.rs | 15 ++++---------- crates/matrix-sdk/src/sliding_sync/view.rs | 23 +++++++++++----------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/crates/matrix-sdk/src/sliding_sync/mod.rs b/crates/matrix-sdk/src/sliding_sync/mod.rs index 0d7cf338f..43fdd4c74 100644 --- a/crates/matrix-sdk/src/sliding_sync/mod.rs +++ b/crates/matrix-sdk/src/sliding_sync/mod.rs @@ -632,7 +632,7 @@ use std::{ pub use client::*; pub use config::*; use futures_core::stream::Stream; -use futures_signals::{signal::Mutable, signal_vec::MutableVec}; +use futures_signals::signal::Mutable; pub use room::*; use ruma::{ api::client::{ @@ -641,7 +641,7 @@ use ruma::{ self, AccountDataConfig, E2EEConfig, ExtensionsConfig, ToDeviceConfig, }, }, - assign, OwnedRoomId, RoomId, UInt, + assign, OwnedRoomId, RoomId, }; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -738,13 +738,6 @@ impl RoomListEntry { } } -type ViewState = Mutable; -type SyncMode = Mutable; -type StringState = Mutable>; -type RangeState = Mutable>; -type RoomsCount = Mutable>; -type RoomsList = Arc>; - /// The Summary of a new SlidingSync Update received #[derive(Debug, Clone)] pub struct UpdateSummary { @@ -766,8 +759,8 @@ pub struct SlidingSync { storage_key: Option, // ------ Internal state - pub(crate) pos: StringState, - delta_token: StringState, + pub(crate) pos: Mutable>, + delta_token: Mutable>, /// The views of this sliding sync instance views: Arc>>, diff --git a/crates/matrix-sdk/src/sliding_sync/view.rs b/crates/matrix-sdk/src/sliding_sync/view.rs index 7fca484dd..ef516662b 100644 --- a/crates/matrix-sdk/src/sliding_sync/view.rs +++ b/crates/matrix-sdk/src/sliding_sync/view.rs @@ -19,8 +19,7 @@ use serde::{Deserialize, Serialize}; use tracing::{debug, error, instrument, trace, warn}; use super::{ - Error, FrozenSlidingSyncRoom, RangeState, RoomListEntry, RoomsCount, RoomsList, - SlidingSyncMode, SlidingSyncRoom, SlidingSyncState, SyncMode, ViewState, + Error, FrozenSlidingSyncRoom, RoomListEntry, SlidingSyncMode, SlidingSyncRoom, SlidingSyncState, }; use crate::Result; @@ -44,9 +43,9 @@ use crate::Result; #[derive(Clone, Debug, Builder)] #[builder(build_fn(name = "finish_build"), pattern = "owned", derive(Clone, Debug))] pub struct SlidingSyncView { - /// Which SyncMode to start this view under + /// Which SlidingSyncMode to start this view under #[builder(setter(custom), default)] - sync_mode: SyncMode, + sync_mode: Mutable, /// Sort the rooms list by this #[builder(default = "SlidingSyncViewBuilder::default_sort()")] @@ -84,19 +83,19 @@ pub struct SlidingSyncView { /// The state this view is in #[builder(private, default)] - pub state: ViewState, + pub state: Mutable, /// The total known number of rooms, #[builder(private, default)] - pub rooms_count: RoomsCount, + pub rooms_count: Mutable>, /// The rooms in order #[builder(private, default)] - pub rooms_list: RoomsList, + pub rooms_list: Arc>, /// The ranges windows of the view #[builder(setter(name = "ranges_raw"), default)] - ranges: RangeState, + ranges: Mutable>, /// Signaling updates on the room list after processing #[builder(private)] @@ -193,26 +192,26 @@ impl SlidingSyncViewBuilder { /// Set the Syncing mode pub fn sync_mode(mut self, sync_mode: SlidingSyncMode) -> Self { - self.sync_mode = Some(SyncMode::new(sync_mode)); + self.sync_mode = Some(Mutable::new(sync_mode)); self } /// Set the ranges to fetch pub fn ranges>(mut self, range: Vec<(U, U)>) -> Self { self.ranges = - Some(RangeState::new(range.into_iter().map(|(a, b)| (a.into(), b.into())).collect())); + Some(Mutable::new(range.into_iter().map(|(a, b)| (a.into(), b.into())).collect())); self } /// Set a single range fetch pub fn set_range>(mut self, from: U, to: U) -> Self { - self.ranges = Some(RangeState::new(vec![(from.into(), to.into())])); + self.ranges = Some(Mutable::new(vec![(from.into(), to.into())])); self } /// Set the ranges to fetch pub fn add_range>(mut self, from: U, to: U) -> Self { - let r = self.ranges.get_or_insert_with(|| RangeState::new(Vec::new())); + let r = self.ranges.get_or_insert_with(|| Mutable::new(Vec::new())); r.lock_mut().push((from.into(), to.into())); self }