Skip to content

Commit 8865e2f

Browse files
MatMaulHywan
authored andcommitted
RoomListLoadingState now yields immediately with current value
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.
1 parent 2fa54e5 commit 8865e2f

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

crates/matrix-sdk-ui/src/room_list_service/room_list.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ impl RoomList {
114114
}
115115

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

121123
/// Get a stream of rooms.

crates/matrix-sdk-ui/tests/integration/room_list_service.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,13 @@ async fn test_sync_resumes_from_previous_state_after_restart() -> Result<(), Err
599599
let sync = room_list.sync();
600600
pin_mut!(sync);
601601

602+
let all_rooms = room_list.all_rooms().await?;
603+
let mut all_rooms_loading_state = all_rooms.loading_state();
604+
605+
// The loading is not loaded.
606+
assert_next_matches!(all_rooms_loading_state, RoomListLoadingState::NotLoaded);
607+
assert_pending!(all_rooms_loading_state);
608+
602609
sync_then_assert_request_and_fake_response! {
603610
[server, room_list, sync]
604611
states = Init => SettingUp,
@@ -627,6 +634,20 @@ async fn test_sync_resumes_from_previous_state_after_restart() -> Result<(), Err
627634
let sync = room_list.sync();
628635
pin_mut!(sync);
629636

637+
let all_rooms = room_list.all_rooms().await?;
638+
let mut all_rooms_loading_state = all_rooms.loading_state();
639+
640+
// Wait on Tokio to run all the tasks. Necessary only when testing.
641+
yield_now().await;
642+
643+
// We already have a state stored so the list should already be loaded
644+
assert_next_matches!(
645+
all_rooms_loading_state,
646+
RoomListLoadingState::Loaded { maximum_number_of_rooms: Some(10) }
647+
);
648+
assert_pending!(all_rooms_loading_state);
649+
650+
// pos has been restored and is used when doing the req
630651
sync_then_assert_request_and_fake_response! {
631652
[server, room_list, sync]
632653
states = Init => SettingUp,
@@ -642,12 +663,22 @@ async fn test_sync_resumes_from_previous_state_after_restart() -> Result<(), Err
642663
"pos": "1",
643664
"lists": {
644665
ALL_ROOMS: {
645-
"count": 10,
666+
"count": 12,
646667
},
647668
},
648669
"rooms": {},
649670
},
650671
};
672+
673+
// Wait on Tokio to run all the tasks. Necessary only when testing.
674+
yield_now().await;
675+
676+
// maximum_number_of_rooms changed so we should get a new loaded state
677+
assert_next_matches!(
678+
all_rooms_loading_state,
679+
RoomListLoadingState::Loaded { maximum_number_of_rooms: Some(12) }
680+
);
681+
assert_pending!(all_rooms_loading_state);
651682
}
652683

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

11411172
// The loading is not loaded.
1142-
assert_matches!(all_rooms_loading_state.get(), RoomListLoadingState::NotLoaded);
1143-
assert_pending!(all_rooms_loading_state);
1173+
assert_next_matches!(all_rooms_loading_state, RoomListLoadingState::NotLoaded);
11441174

11451175
sync_then_assert_request_and_fake_response! {
11461176
[server, room_list, sync]
@@ -1246,11 +1276,10 @@ async fn test_loading_states() -> Result<(), Error> {
12461276
pin_mut!(sync);
12471277

12481278
// The loading state is loaded! Indeed, there is data loaded from the cache.
1249-
assert_matches!(
1250-
all_rooms_loading_state.get(),
1279+
assert_next_matches!(
1280+
all_rooms_loading_state,
12511281
RoomListLoadingState::Loaded { maximum_number_of_rooms: Some(12) }
12521282
);
1253-
assert_pending!(all_rooms_loading_state);
12541283

12551284
sync_then_assert_request_and_fake_response! {
12561285
[server, room_list, sync]

0 commit comments

Comments
 (0)