mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-18 13:40:55 -04:00
feat(room list service): skip the initial state when an initial pos is set
This commit is contained in:
@@ -177,7 +177,17 @@ impl RoomListService {
|
||||
// Eagerly subscribe the event cache to sync responses.
|
||||
client.event_cache().subscribe()?;
|
||||
|
||||
Ok(Self { client, sliding_sync, state_machine: StateMachine::new() })
|
||||
let state_machine = StateMachine::new();
|
||||
|
||||
// If the sliding sync has successfully restored a sync position, skip the
|
||||
// waiting for the initial sync, and set the state to `SettingUp`; this
|
||||
// way, the first sync will move us to the steady state, and update the
|
||||
// sliding sync list to use the growing sync mode.
|
||||
if sliding_sync.has_pos().await {
|
||||
state_machine.set(State::SettingUp);
|
||||
}
|
||||
|
||||
Ok(Self { client, sliding_sync, state_machine })
|
||||
}
|
||||
|
||||
/// Start to sync the room list.
|
||||
|
||||
@@ -107,8 +107,8 @@ impl StateMachine {
|
||||
self.state.subscribe()
|
||||
}
|
||||
|
||||
/// Transition to the next state, and execute the associated transition's
|
||||
/// [`Actions`].
|
||||
/// Transition to the next state, and execute the necessary transition on
|
||||
/// the sliding sync list.
|
||||
pub(super) async fn next(&self, sliding_sync: &SlidingSync) -> Result<State, Error> {
|
||||
use State::*;
|
||||
|
||||
|
||||
@@ -1292,19 +1292,21 @@ async fn test_loading_states() -> Result<(), Error> {
|
||||
RoomListLoadingState::Loaded { maximum_number_of_rooms: Some(12) }
|
||||
);
|
||||
|
||||
// The sync skips the `Init` state, and immediately starts in the `SettingUp`
|
||||
// state, as the sync `pos`ition marker was set.
|
||||
sync_then_assert_request_and_fake_response! {
|
||||
[server, room_list, sync]
|
||||
states = Init => SettingUp,
|
||||
states = SettingUp => Running,
|
||||
assert request >= {
|
||||
"lists": {
|
||||
ALL_ROOMS: {
|
||||
"ranges": [[0, 19]],
|
||||
"ranges": [[0, 11]],
|
||||
"timeline_limit": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
respond with = {
|
||||
"pos": "0",
|
||||
"pos": "3",
|
||||
"lists": {
|
||||
ALL_ROOMS: {
|
||||
"count": 13, // 1 more room
|
||||
|
||||
@@ -124,6 +124,12 @@ impl SlidingSync {
|
||||
Self { inner: Arc::new(inner) }
|
||||
}
|
||||
|
||||
/// Whether the current sliding sync instance has set a sync position
|
||||
/// marker.
|
||||
pub async fn has_pos(&self) -> bool {
|
||||
self.inner.position.lock().await.pos.is_some()
|
||||
}
|
||||
|
||||
async fn cache_to_storage(&self, position: &SlidingSyncPositionMarkers) -> Result<()> {
|
||||
cache::store_sliding_sync_state(self, position).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user