refactor(sdk): Inline Mutable type aliases

This commit is contained in:
Jonas Platte
2023-02-20 12:30:31 +01:00
committed by Jonas Platte
parent a112076664
commit e92841d6bc
2 changed files with 15 additions and 23 deletions

View File

@@ -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<SlidingSyncState>;
type SyncMode = Mutable<SlidingSyncMode>;
type StringState = Mutable<Option<String>>;
type RangeState = Mutable<Vec<(UInt, UInt)>>;
type RoomsCount = Mutable<Option<u32>>;
type RoomsList = Arc<MutableVec<RoomListEntry>>;
/// The Summary of a new SlidingSync Update received
#[derive(Debug, Clone)]
pub struct UpdateSummary {
@@ -766,8 +759,8 @@ pub struct SlidingSync {
storage_key: Option<String>,
// ------ Internal state
pub(crate) pos: StringState,
delta_token: StringState,
pub(crate) pos: Mutable<Option<String>>,
delta_token: Mutable<Option<String>>,
/// The views of this sliding sync instance
views: Arc<StdRwLock<BTreeMap<String, SlidingSyncView>>>,

View File

@@ -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<SlidingSyncMode>,
/// 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<SlidingSyncState>,
/// The total known number of rooms,
#[builder(private, default)]
pub rooms_count: RoomsCount,
pub rooms_count: Mutable<Option<u32>>,
/// The rooms in order
#[builder(private, default)]
pub rooms_list: RoomsList,
pub rooms_list: Arc<MutableVec<RoomListEntry>>,
/// The ranges windows of the view
#[builder(setter(name = "ranges_raw"), default)]
ranges: RangeState,
ranges: Mutable<Vec<(UInt, UInt)>>,
/// 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<U: Into<UInt>>(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<U: Into<UInt>>(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<U: Into<UInt>>(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
}