mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-04-27 10:39:25 -04:00
feat(ui): RoomList dynamic entries simplifications
feat(ui): `RoomList` dynamic entries simplifications
This commit is contained in:
@@ -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<AsyncCell<BoxedFilterFn>>,
|
||||
page_size: usize,
|
||||
limit: SharedObservable<usize>,
|
||||
maximum_number_of_rooms: Mutex<Subscriber<Option<u32>>>,
|
||||
maximum_number_of_rooms: Subscriber<Option<u32>>,
|
||||
}
|
||||
|
||||
impl RoomListDynamicEntriesController {
|
||||
@@ -221,12 +218,7 @@ impl RoomListDynamicEntriesController {
|
||||
limit_stream: SharedObservable<usize>,
|
||||
maximum_number_of_rooms: Subscriber<Option<u32>>,
|
||||
) -> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user