From ff4af894e4cd17506e92dccdb0764344cd46e17c Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 26 Jun 2024 16:35:51 +0200 Subject: [PATCH] feat(ui): The `RoomList` uses sorters! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch “installs” the sorters API for the `RoomList`. --- crates/matrix-sdk-base/src/sliding_sync.rs | 7 ++++++- .../matrix-sdk-ui/src/room_list_service/room_list.rs | 12 ++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/matrix-sdk-base/src/sliding_sync.rs b/crates/matrix-sdk-base/src/sliding_sync.rs index 3415147f6..2cd0dbe8a 100644 --- a/crates/matrix-sdk-base/src/sliding_sync.rs +++ b/crates/matrix-sdk-base/src/sliding_sync.rs @@ -292,7 +292,12 @@ impl BaseClient { trace!("ready to submit changes to store"); store.save_changes(&changes).await?; - self.apply_changes(&changes, false); + self.apply_changes( + &changes, + // The changes may result in a latest event update, which should trigger a room list + // re-ordering. This the room list should be notified by these changes. + true, + ); trace!("applied changes"); // Now that all the rooms information have been saved, update the display name 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 baa1966e0..c5e3d891e 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 @@ -28,7 +28,11 @@ use matrix_sdk::{ use matrix_sdk_base::RoomInfoUpdate; use tokio::{select, sync::broadcast}; -use super::{filters::BoxedFilterFn, Error, Room, State}; +use super::{ + filters::BoxedFilterFn, + sorters::{new_sorter_name, new_sorter_or, new_sorter_recency}, + Error, Room, State, +}; /// A `RoomList` represents a list of rooms, from a /// [`RoomListService`](super::RoomListService). @@ -161,6 +165,10 @@ impl RoomList { let (values, stream) = (raw_values, merged_stream) .filter(filter_fn) + .sort_by(new_sorter_or(vec![ + Box::new(new_sorter_recency()), + Box::new(new_sorter_name()) + ])) .dynamic_limit_with_initial_value(page_size, limit_stream.clone()); // Clearing the stream before chaining with the real stream. @@ -196,7 +204,7 @@ fn merge_stream_and_receiver( // Search list for the updated room for (index, room) in raw_current_values.iter().enumerate() { - if room.room_id() == &update.room_id { + if room.room_id() == update.room_id { let update = VectorDiff::Set { index, value: raw_current_values[index].clone() }; yield vec![update]; break;