diff --git a/crates/matrix-sdk-ui/src/room_list_service/room_list.rs b/crates/matrix-sdk-ui/src/room_list_service/room_list.rs index 710bf4bac..d69440efe 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/room_list.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/room_list.rs @@ -12,10 +12,7 @@ // See the License for that specific language governing permissions and // limitations under the License. -use std::{ - future::ready, - sync::{Arc, Mutex}, -}; +use std::{future::ready, sync::Arc}; use async_cell::sync::AsyncCell; use async_rx::StreamExt as _; @@ -138,7 +135,7 @@ impl RoomList { let dynamic_entries_controller = RoomListDynamicEntriesController::new( filter_fn_cell.clone(), page_size, - limit.clone(), + limit, list.maximum_number_of_rooms_stream(), ); @@ -211,7 +208,7 @@ pub struct RoomListDynamicEntriesController { filter: Arc>, page_size: usize, limit: SharedObservable, - maximum_number_of_rooms: Mutex>>, + maximum_number_of_rooms: Subscriber>, } impl RoomListDynamicEntriesController { @@ -221,12 +218,7 @@ impl RoomListDynamicEntriesController { limit_stream: SharedObservable, maximum_number_of_rooms: Subscriber>, ) -> Self { - Self { - filter, - page_size, - limit: limit_stream, - maximum_number_of_rooms: Mutex::new(maximum_number_of_rooms), - } + Self { filter, page_size, limit: limit_stream, maximum_number_of_rooms } } /// Set the filter. @@ -251,7 +243,7 @@ impl RoomListDynamicEntriesController { /// Add one page, i.e. view `page_size` more entries in the room list if /// any. pub fn add_one_page(&self) { - let Some(max) = self.maximum_number_of_rooms.lock().unwrap().next_now() else { + let Some(max) = self.maximum_number_of_rooms.get() else { return; }; @@ -263,13 +255,13 @@ impl RoomListDynamicEntriesController { // `max - limit < page_size`, and that's perfectly fine. It's OK to have a // `limit` greater than `max`, but it's not OK to increase the limit // indefinitely. - self.limit.set(limit + self.page_size); + self.limit.set_if_not_eq(limit + self.page_size); } } /// Reset the one page, i.e. forget all pages and move back to the first /// page. pub fn reset_to_one_page(&self) { - self.limit.set(self.page_size); + self.limit.set_if_not_eq(self.page_size); } } diff --git a/crates/matrix-sdk-ui/tests/integration/room_list_service.rs b/crates/matrix-sdk-ui/tests/integration/room_list_service.rs index 4805aebf9..30709fe17 100644 --- a/crates/matrix-sdk-ui/tests/integration/room_list_service.rs +++ b/crates/matrix-sdk-ui/tests/integration/room_list_service.rs @@ -1851,6 +1851,10 @@ async fn test_dynamic_entries_stream() -> Result<(), Error> { } assert_pending!(dynamic_entries_stream); + // Let's reset to one page again, it should do nothing. + dynamic_entries.reset_to_one_page(); + assert_pending!(dynamic_entries_stream); + // Let's ask one more page again, because it's fun. dynamic_entries.add_one_page();