Skip to content

Commit

Permalink
RoomListLoadingState now yields immediately with current value
Browse files Browse the repository at this point in the history
This fixes a problem when doing an incremental sync at launch,
where `NotLoaded` event	would not be dispatched	until data became
available or timeout is	reached, leading to app waiting for it.
  • Loading branch information
MatMaul authored and Hywan committed Nov 5, 2024
1 parent 2fa54e5 commit 8865e2f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
4 changes: 3 additions & 1 deletion crates/matrix-sdk-ui/src/room_list_service/room_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ impl RoomList {
}

/// Get a subscriber to the room list loading state.
///
/// This method will send out the current loading state as the first update.
pub fn loading_state(&self) -> Subscriber<RoomListLoadingState> {
self.loading_state.subscribe()
self.loading_state.subscribe_reset()
}

/// Get a stream of rooms.
Expand Down
41 changes: 35 additions & 6 deletions crates/matrix-sdk-ui/tests/integration/room_list_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,13 @@ async fn test_sync_resumes_from_previous_state_after_restart() -> Result<(), Err
let sync = room_list.sync();
pin_mut!(sync);

let all_rooms = room_list.all_rooms().await?;
let mut all_rooms_loading_state = all_rooms.loading_state();

// The loading is not loaded.
assert_next_matches!(all_rooms_loading_state, RoomListLoadingState::NotLoaded);
assert_pending!(all_rooms_loading_state);

sync_then_assert_request_and_fake_response! {
[server, room_list, sync]
states = Init => SettingUp,
Expand Down Expand Up @@ -627,6 +634,20 @@ async fn test_sync_resumes_from_previous_state_after_restart() -> Result<(), Err
let sync = room_list.sync();
pin_mut!(sync);

let all_rooms = room_list.all_rooms().await?;
let mut all_rooms_loading_state = all_rooms.loading_state();

// Wait on Tokio to run all the tasks. Necessary only when testing.
yield_now().await;

// We already have a state stored so the list should already be loaded
assert_next_matches!(
all_rooms_loading_state,
RoomListLoadingState::Loaded { maximum_number_of_rooms: Some(10) }
);
assert_pending!(all_rooms_loading_state);

// pos has been restored and is used when doing the req
sync_then_assert_request_and_fake_response! {
[server, room_list, sync]
states = Init => SettingUp,
Expand All @@ -642,12 +663,22 @@ async fn test_sync_resumes_from_previous_state_after_restart() -> Result<(), Err
"pos": "1",
"lists": {
ALL_ROOMS: {
"count": 10,
"count": 12,
},
},
"rooms": {},
},
};

// Wait on Tokio to run all the tasks. Necessary only when testing.
yield_now().await;

// maximum_number_of_rooms changed so we should get a new loaded state
assert_next_matches!(
all_rooms_loading_state,
RoomListLoadingState::Loaded { maximum_number_of_rooms: Some(12) }
);
assert_pending!(all_rooms_loading_state);
}

Ok(())
Expand Down Expand Up @@ -1139,8 +1170,7 @@ async fn test_loading_states() -> Result<(), Error> {
let mut all_rooms_loading_state = all_rooms.loading_state();

// The loading is not loaded.
assert_matches!(all_rooms_loading_state.get(), RoomListLoadingState::NotLoaded);
assert_pending!(all_rooms_loading_state);
assert_next_matches!(all_rooms_loading_state, RoomListLoadingState::NotLoaded);

sync_then_assert_request_and_fake_response! {
[server, room_list, sync]
Expand Down Expand Up @@ -1246,11 +1276,10 @@ async fn test_loading_states() -> Result<(), Error> {
pin_mut!(sync);

// The loading state is loaded! Indeed, there is data loaded from the cache.
assert_matches!(
all_rooms_loading_state.get(),
assert_next_matches!(
all_rooms_loading_state,
RoomListLoadingState::Loaded { maximum_number_of_rooms: Some(12) }
);
assert_pending!(all_rooms_loading_state);

sync_then_assert_request_and_fake_response! {
[server, room_list, sync]
Expand Down

0 comments on commit 8865e2f

Please sign in to comment.