From 0bbefa000b05ae6cf9fa2df59b50e3cfd02d21d0 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 18 Sep 2025 15:11:26 +0200 Subject: [PATCH] chore(ui): Rename `room_list_service::Room` to `RoomListItem`. This patch renames the `Room` type in `room_list_service` to `RoomListItem` to avoid confusion with `matrix_sdk::Room`. --- .../src/room_list_service/filters/category.rs | 14 ++--- .../filters/deduplicate_versions.rs | 18 +++--- .../room_list_service/filters/favourite.rs | 12 ++-- .../src/room_list_service/filters/invite.rs | 8 +-- .../src/room_list_service/filters/joined.rs | 8 +-- .../room_list_service/filters/low_priority.rs | 8 +-- .../src/room_list_service/filters/mod.rs | 8 +-- .../src/room_list_service/filters/non_left.rs | 8 +-- .../src/room_list_service/filters/space.rs | 8 +-- .../src/room_list_service/filters/unread.rs | 19 +++--- .../src/room_list_service/mod.rs | 6 +- .../src/room_list_service/room_list.rs | 58 +++++++++---------- .../room_list_service/sorters/latest_event.rs | 12 ++-- .../src/room_list_service/sorters/mod.rs | 6 +- .../src/room_list_service/sorters/name.rs | 13 +++-- .../src/room_list_service/sorters/recency.rs | 18 +++--- labs/multiverse/src/widgets/room_list.rs | 2 +- 17 files changed, 114 insertions(+), 112 deletions(-) diff --git a/crates/matrix-sdk-ui/src/room_list_service/filters/category.rs b/crates/matrix-sdk-ui/src/room_list_service/filters/category.rs index 5fff964ca..cab1db365 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/filters/category.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/filters/category.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use super::{super::Room, Filter}; +use super::{super::RoomListItem, Filter}; /// An enum to represent whether a room is about “people” (strictly 2 users) or /// “group” (1 or more than 2 users). @@ -34,9 +34,9 @@ type DirectTargetsLength = usize; /// _Direct targets_ mean the number of users in a direct room, except us. /// So if it returns 1, it means there are 2 users in the direct room. -fn matches(number_of_direct_targets: F, room: &Room, expected_kind: RoomCategory) -> bool +fn matches(number_of_direct_targets: F, room: &RoomListItem, expected_kind: RoomCategory) -> bool where - F: Fn(&Room) -> Option, + F: Fn(&RoomListItem) -> Option, { let kind = match number_of_direct_targets(room) { // If 1, we are sure it's a direct room between two users. It's the strict @@ -59,7 +59,7 @@ where /// `expected_category`. The category is defined by [`RoomCategory`], see this /// type to learn more. pub fn new_filter(expected_category: RoomCategory) -> impl Filter { - let number_of_direct_targets = move |room: &Room| Some(room.direct_targets_length()); + let number_of_direct_targets = move |room: &RoomListItem| Some(room.direct_targets_length()); move |room| -> bool { matches(number_of_direct_targets, room, expected_category) } } @@ -79,7 +79,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - let number_of_direct_targets = |_room: &Room| Some(42); + let number_of_direct_targets = |_room: &RoomListItem| Some(42); // Expect `People`. { @@ -101,7 +101,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - let number_of_direct_targets = |_room: &Room| Some(1); + let number_of_direct_targets = |_room: &RoomListItem| Some(1); // Expect `People`. { @@ -123,7 +123,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - let number_of_direct_targets = |_room: &Room| None; + let number_of_direct_targets = |_room: &RoomListItem| None; assert!(matches(number_of_direct_targets, &room, RoomCategory::Group).not()); } diff --git a/crates/matrix-sdk-ui/src/room_list_service/filters/deduplicate_versions.rs b/crates/matrix-sdk-ui/src/room_list_service/filters/deduplicate_versions.rs index 74d5a262e..c6c38de84 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/filters/deduplicate_versions.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/filters/deduplicate_versions.rs @@ -14,13 +14,13 @@ use matrix_sdk_base::RoomState; -use super::{super::Room, Filter}; +use super::{super::RoomListItem, Filter}; type SuccessorRoomState = RoomState; -fn matches(state: F, room: &Room) -> bool +fn matches(state: F, room: &RoomListItem) -> bool where - F: Fn(&Room) -> (RoomState, Option), + F: Fn(&RoomListItem) -> (RoomState, Option), { let (room_state, successor_room_state) = state(room); @@ -66,7 +66,7 @@ where /// /// All other rooms are filtered out. pub fn new_filter() -> impl Filter { - let state = |room: &Room| { + let state = |room: &RoomListItem| { ( room.cached_state, room.successor_room() @@ -94,7 +94,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - assert!(matches(|_room: &Room| (RoomState::Joined, None), &room)); + assert!(matches(|_room: &RoomListItem| (RoomState::Joined, None), &room)); } #[async_test] @@ -174,7 +174,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - let state = |_: &Room| (RoomState::Left, None); + let state = |_: &RoomListItem| (RoomState::Left, None); assert!(matches(state, &room)); } @@ -183,7 +183,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - let state = |_: &Room| (RoomState::Invited, None); + let state = |_: &RoomListItem| (RoomState::Invited, None); assert!(matches(state, &room)); } @@ -192,7 +192,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - let state = |_: &Room| (RoomState::Banned, None); + let state = |_: &RoomListItem| (RoomState::Banned, None); assert!(matches(state, &room)); } @@ -201,7 +201,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - let state = |_: &Room| (RoomState::Knocked, None); + let state = |_: &RoomListItem| (RoomState::Knocked, None); assert!(matches(state, &room)); } } diff --git a/crates/matrix-sdk-ui/src/room_list_service/filters/favourite.rs b/crates/matrix-sdk-ui/src/room_list_service/filters/favourite.rs index 608c07a5a..ac09d83de 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/filters/favourite.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/filters/favourite.rs @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -use super::{super::Room, Filter}; +use super::{super::RoomListItem, Filter}; -fn matches(is_favourite: F, room: &Room) -> bool +fn matches(is_favourite: F, room: &RoomListItem) -> bool where - F: Fn(&Room) -> bool, + F: Fn(&RoomListItem) -> bool, { is_favourite(room) } @@ -24,7 +24,7 @@ where /// Create a new filter that will filter out rooms that are not marked as /// favourite (see [`matrix_sdk_base::Room::is_favourite`]). pub fn new_filter() -> impl Filter { - |room| -> bool { matches(|room: &Room| room.is_favourite(), room) } + |room| -> bool { matches(|room: &RoomListItem| room.is_favourite(), room) } } #[cfg(test)] @@ -42,7 +42,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - assert!(matches(|_: &Room| true, &room)); + assert!(matches(|_: &RoomListItem| true, &room)); } #[async_test] @@ -50,6 +50,6 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - assert!(matches(|_: &Room| false, &room).not()); + assert!(matches(|_: &RoomListItem| false, &room).not()); } } diff --git a/crates/matrix-sdk-ui/src/room_list_service/filters/invite.rs b/crates/matrix-sdk-ui/src/room_list_service/filters/invite.rs index 7dadb83ce..c40879c06 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/filters/invite.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/filters/invite.rs @@ -14,11 +14,11 @@ use matrix_sdk_base::RoomState; -use super::{super::Room, Filter}; +use super::{super::RoomListItem, Filter}; -fn matches(state: F, room: &Room) -> bool +fn matches(state: F, room: &RoomListItem) -> bool where - F: Fn(&Room) -> RoomState, + F: Fn(&RoomListItem) -> RoomState, { state(room) == RoomState::Invited } @@ -26,7 +26,7 @@ where /// Create a new filter that will filter out rooms that are not invites (see /// [`matrix_sdk_base::RoomState::Invited`]). pub fn new_filter() -> impl Filter { - let state = |room: &Room| room.cached_state; + let state = |room: &RoomListItem| room.cached_state; move |room| -> bool { matches(state, room) } } diff --git a/crates/matrix-sdk-ui/src/room_list_service/filters/joined.rs b/crates/matrix-sdk-ui/src/room_list_service/filters/joined.rs index a30862bf4..e58beba88 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/filters/joined.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/filters/joined.rs @@ -14,11 +14,11 @@ use matrix_sdk_base::RoomState; -use super::{super::Room, Filter}; +use super::{super::RoomListItem, Filter}; -fn matches(state: F, room: &Room) -> bool +fn matches(state: F, room: &RoomListItem) -> bool where - F: Fn(&Room) -> RoomState, + F: Fn(&RoomListItem) -> RoomState, { state(room) == RoomState::Joined } @@ -26,7 +26,7 @@ where /// Create a new filter that will filter out rooms that are not joined (see /// [`matrix_sdk_base::RoomState::Joined`]). pub fn new_filter() -> impl Filter { - let state = |room: &Room| room.cached_state; + let state = |room: &RoomListItem| room.cached_state; move |room| -> bool { matches(state, room) } } diff --git a/crates/matrix-sdk-ui/src/room_list_service/filters/low_priority.rs b/crates/matrix-sdk-ui/src/room_list_service/filters/low_priority.rs index cbdeac770..a95de2b46 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/filters/low_priority.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/filters/low_priority.rs @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -use super::{super::Room, Filter}; +use super::{super::RoomListItem, Filter}; -fn matches(is_low_priority: F, room: &Room) -> bool +fn matches(is_low_priority: F, room: &RoomListItem) -> bool where - F: Fn(&Room) -> bool, + F: Fn(&RoomListItem) -> bool, { is_low_priority(room) } @@ -24,7 +24,7 @@ where /// Create a new filter that will filter out rooms that are not marked as /// low priority (see [`matrix_sdk_base::Room::is_low_priority`]). pub fn new_filter() -> impl Filter { - let is_low_priority = |room: &Room| room.is_low_priority(); + let is_low_priority = |room: &RoomListItem| room.is_low_priority(); move |room| -> bool { matches(is_low_priority, room) } } diff --git a/crates/matrix-sdk-ui/src/room_list_service/filters/mod.rs b/crates/matrix-sdk-ui/src/room_list_service/filters/mod.rs index 9de627359..820820592 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/filters/mod.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/filters/mod.rs @@ -95,14 +95,14 @@ use wiremock::{ matchers::{header, method, path}, }; -use super::Room; +use super::RoomListItem; /// A trait “alias” that represents a _filter_. /// /// A filter is simply a function that receives a `&Room` and returns a `bool`. -pub trait Filter: Fn(&Room) -> bool {} +pub trait Filter: Fn(&RoomListItem) -> bool {} -impl Filter for F where F: Fn(&Room) -> bool {} +impl Filter for F where F: Fn(&RoomListItem) -> bool {} /// Type alias for a boxed filter function. #[cfg(not(target_family = "wasm"))] @@ -122,7 +122,7 @@ pub(super) async fn new_rooms( room_ids: [&RoomId; N], client: &Client, server: &MockServer, -) -> [Room; N] { +) -> [RoomListItem; N] { let mut response_builder = SyncResponseBuilder::default(); for room_id in room_ids { diff --git a/crates/matrix-sdk-ui/src/room_list_service/filters/non_left.rs b/crates/matrix-sdk-ui/src/room_list_service/filters/non_left.rs index 27bf49067..f9966330d 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/filters/non_left.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/filters/non_left.rs @@ -14,11 +14,11 @@ use matrix_sdk_base::RoomState; -use super::{super::Room, Filter}; +use super::{super::RoomListItem, Filter}; -fn matches(state: F, room: &Room) -> bool +fn matches(state: F, room: &RoomListItem) -> bool where - F: Fn(&Room) -> RoomState, + F: Fn(&RoomListItem) -> RoomState, { match state(room) { RoomState::Joined | RoomState::Invited | RoomState::Knocked => true, @@ -28,7 +28,7 @@ where /// Create a new filter that will filter out left rooms. pub fn new_filter() -> impl Filter { - let state = |room: &Room| room.cached_state; + let state = |room: &RoomListItem| room.cached_state; move |room| -> bool { matches(state, room) } } diff --git a/crates/matrix-sdk-ui/src/room_list_service/filters/space.rs b/crates/matrix-sdk-ui/src/room_list_service/filters/space.rs index bcd5f585c..43eb778a5 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/filters/space.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/filters/space.rs @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -use super::{super::Room, Filter}; +use super::{super::RoomListItem, Filter}; -fn matches(is_space: F, room: &Room) -> bool +fn matches(is_space: F, room: &RoomListItem) -> bool where - F: Fn(&Room) -> bool, + F: Fn(&RoomListItem) -> bool, { is_space(room) } @@ -24,7 +24,7 @@ where /// Create a new filter that will filter out rooms that are spaces, i.e. /// room with a `room_type` of `m.space` as defined in pub fn new_filter() -> impl Filter { - let is_space = |room: &Room| room.cached_is_space; + let is_space = |room: &RoomListItem| room.cached_is_space; move |room| -> bool { matches(is_space, room) } } diff --git a/crates/matrix-sdk-ui/src/room_list_service/filters/unread.rs b/crates/matrix-sdk-ui/src/room_list_service/filters/unread.rs index e9d70de75..6f9c9d189 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/filters/unread.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/filters/unread.rs @@ -14,13 +14,13 @@ use matrix_sdk_base::read_receipts::RoomReadReceipts; -use super::{super::Room, Filter}; +use super::{super::RoomListItem, Filter}; type IsMarkedUnread = bool; -fn matches(read_receipts_and_unread: F, room: &Room) -> bool +fn matches(read_receipts_and_unread: F, room: &RoomListItem) -> bool where - F: Fn(&Room) -> (RoomReadReceipts, IsMarkedUnread), + F: Fn(&RoomListItem) -> (RoomReadReceipts, IsMarkedUnread), { let (read_receipts, is_marked_unread) = read_receipts_and_unread(room); @@ -30,7 +30,8 @@ where /// Create a new filter that will filter out rooms that have no unread /// notifications (different from unread messages), or is not marked as unread. pub fn new_filter() -> impl Filter { - let read_receipts_and_unread = |room: &Room| (room.read_receipts(), room.is_marked_unread()); + let read_receipts_and_unread = + |room: &RoomListItem| (room.read_receipts(), room.is_marked_unread()); move |room_list_entry| -> bool { matches(read_receipts_and_unread, room_list_entry) } } @@ -52,7 +53,7 @@ mod tests { let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; for is_marked_as_unread in [true, false] { - let read_receipts_and_unread = |_: &Room| { + let read_receipts_and_unread = |_: &RoomListItem| { let mut read_receipts = RoomReadReceipts::default(); read_receipts.num_unread = 42; read_receipts.num_notifications = 42; @@ -69,7 +70,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - let read_receipts_and_unread = |_: &Room| { + let read_receipts_and_unread = |_: &RoomListItem| { let mut read_receipts = RoomReadReceipts::default(); read_receipts.num_unread = 42; read_receipts.num_notifications = 0; @@ -85,7 +86,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - let read_receipts_and_unread = |_: &Room| { + let read_receipts_and_unread = |_: &RoomListItem| { let mut read_receipts = RoomReadReceipts::default(); read_receipts.num_unread = 42; read_receipts.num_notifications = 0; @@ -101,7 +102,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - let read_receipts_and_unread = |_: &Room| (RoomReadReceipts::default(), false); + let read_receipts_and_unread = |_: &RoomListItem| (RoomReadReceipts::default(), false); assert!(matches(read_receipts_and_unread, &room).not()); } @@ -111,7 +112,7 @@ mod tests { let (client, server) = logged_in_client_with_server().await; let [room] = new_rooms([room_id!("!a:b.c")], &client, &server).await; - let read_receipts_and_unread = |_: &Room| (RoomReadReceipts::default(), true); + let read_receipts_and_unread = |_: &RoomListItem| (RoomReadReceipts::default(), true); assert!(matches(read_receipts_and_unread, &room)); } diff --git a/crates/matrix-sdk-ui/src/room_list_service/mod.rs b/crates/matrix-sdk-ui/src/room_list_service/mod.rs index 2228cc52a..3331b5808 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/mod.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/mod.rs @@ -62,7 +62,7 @@ use async_stream::stream; use eyeball::Subscriber; use futures_util::{Stream, StreamExt, pin_mut}; use matrix_sdk::{ - Client, Error as SlidingSyncError, SlidingSync, SlidingSyncList, SlidingSyncMode, + Client, Error as SlidingSyncError, Room, SlidingSync, SlidingSyncList, SlidingSyncMode, event_cache::EventCacheError, timeout::timeout, }; pub use room_list::*; @@ -420,8 +420,8 @@ impl RoomListService { self.list_for(ALL_ROOMS_LIST_NAME).await } - /// Get a [`Room`][matrix_sdk::Room] if it exists. - pub fn room(&self, room_id: &RoomId) -> Result { + /// Get a [`Room`] if it exists. + pub fn room(&self, room_id: &RoomId) -> Result { self.client.get_room(room_id).ok_or_else(|| Error::RoomNotFound(room_id.to_owned())) } 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 3c61d5041..eeb236614 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 @@ -22,7 +22,7 @@ use eyeball_im::{Vector, VectorDiff}; use eyeball_im_util::vector::VectorObserverExt; use futures_util::{Stream, StreamExt as _, pin_mut, stream}; use matrix_sdk::{ - Client, RoomRecencyStamp, RoomState, SlidingSync, SlidingSyncList, + Client, Room, RoomRecencyStamp, RoomState, SlidingSync, SlidingSyncList, executor::{JoinHandle, spawn}, }; use matrix_sdk_base::RoomInfoNotableUpdate; @@ -121,10 +121,7 @@ impl RoomList { } /// Get a stream of rooms. - fn entries( - &self, - ) -> (Vector, impl Stream>> + '_) - { + fn entries(&self) -> (Vector, impl Stream>> + '_) { self.client.rooms_stream() } @@ -142,7 +139,8 @@ impl RoomList { pub fn entries_with_dynamic_adapters( &self, page_size: usize, - ) -> (impl Stream>> + '_, RoomListDynamicEntriesController) { + ) -> (impl Stream>> + '_, RoomListDynamicEntriesController) + { let room_info_notable_update_receiver = self.client.room_info_notable_update_receiver(); let list = self.sliding_sync_list.clone(); @@ -163,7 +161,7 @@ impl RoomList { let filter_fn = filter_fn_cell.take().await; let (raw_values, raw_stream) = self.entries(); - let values = raw_values.into_iter().map(Into::into).collect::>(); + let values = raw_values.into_iter().map(Into::into).collect::>(); // Combine normal stream events with other updates from rooms let stream = merge_stream_and_receiver(values.clone(), raw_stream, room_info_notable_update_receiver.resubscribe()); @@ -200,10 +198,10 @@ impl RoomList { /// knows where all rooms are. When the receiver is triggered, a Set operation /// for the room position is inserted to the stream. fn merge_stream_and_receiver( - mut current_values: Vector, - raw_stream: impl Stream>>, + mut current_values: Vector, + raw_stream: impl Stream>>, mut room_info_notable_update_receiver: broadcast::Receiver, -) -> impl Stream>> { +) -> impl Stream>> { stream! { pin_mut!(raw_stream); @@ -214,7 +212,7 @@ fn merge_stream_and_receiver( diffs = raw_stream.next() => { if let Some(diffs) = diffs { - let diffs = diffs.into_iter().map(|diff| diff.map(Room::from)).collect::>(); + let diffs = diffs.into_iter().map(|diff| diff.map(RoomListItem::from)).collect::>(); for diff in &diffs { diff.clone().map(|room| { @@ -362,44 +360,44 @@ impl RoomListDynamicEntriesController { } } -/// A `Room` facade type that derefs to [`matrix_sdk::Room`] and that caches -/// data from [`RoomInfo`]. +/// A facade type that derefs to [`Room`] and that caches data from +/// [`RoomInfo`]. /// /// Why caching data? [`RoomInfo`] is behind a lock. Every time a filter or a -/// sorter calls a method on [`matrix_sdk::Room`], it's likely to hit the lock -/// in front of [`RoomInfo`]. It creates a big contention. By caching the data, -/// it avoids hitting the lock, improving the performance greatly. +/// sorter calls a method on [`Room`], it's likely to hit the lock in front of +/// [`RoomInfo`]. It creates a big contention. By caching the data, it avoids +/// hitting the lock, improving the performance greatly. /// /// Data are refreshed in `merge_stream_and_receiver` (private function). /// /// [`RoomInfo`]: matrix_sdk::RoomInfo #[derive(Clone, Debug)] -pub struct Room { +pub struct RoomListItem { /// The inner room. - inner: matrix_sdk::Room, + inner: Room, - /// Cache of `matrix_sdk::Room::new_latest_event_timestamp`. + /// Cache of `Room::new_latest_event_timestamp`. pub(super) cached_latest_event_timestamp: Option, - /// Cache of `matrix_sdk::Room::new_latest_event_is_local`. + /// Cache of `Room::new_latest_event_is_local`. pub(super) cached_latest_event_is_local: bool, - /// Cache of `matrix_sdk::Room::recency_stamp`. + /// Cache of `Room::recency_stamp`. pub(super) cached_recency_stamp: Option, - /// Cache of `matrix_sdk::Room::cached_display_name`, already as a string. + /// Cache of `Room::cached_display_name`, already as a string. pub(super) cached_display_name: Option, - /// Cache of `matrix_sdk::Room::is_space`. + /// Cache of `Room::is_space`. pub(super) cached_is_space: bool, - // Cache of `matrix_sdk::Room::state`. + // Cache of `Room::state`. pub(super) cached_state: RoomState, } -impl Room { +impl RoomListItem { /// Deconstruct to the inner room value. - pub fn into_inner(self) -> matrix_sdk::Room { + pub fn into_inner(self) -> Room { self.inner } @@ -414,8 +412,8 @@ impl Room { } } -impl From for Room { - fn from(inner: matrix_sdk::Room) -> Self { +impl From for RoomListItem { + fn from(inner: Room) -> Self { let cached_latest_event_timestamp = inner.new_latest_event_timestamp(); let cached_latest_event_is_local = inner.new_latest_event_is_local(); let cached_recency_stamp = inner.recency_stamp(); @@ -435,8 +433,8 @@ impl From for Room { } } -impl Deref for Room { - type Target = matrix_sdk::Room; +impl Deref for RoomListItem { + type Target = Room; fn deref(&self) -> &Self::Target { &self.inner diff --git a/crates/matrix-sdk-ui/src/room_list_service/sorters/latest_event.rs b/crates/matrix-sdk-ui/src/room_list_service/sorters/latest_event.rs index fe14f2f1f..ef64452f7 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/sorters/latest_event.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/sorters/latest_event.rs @@ -14,11 +14,11 @@ use std::cmp::Ordering; -use super::{Room, Sorter}; +use super::{RoomListItem, Sorter}; -fn cmp(are_latest_events_locals: F, left: &Room, right: &Room) -> Ordering +fn cmp(are_latest_events_locals: F, left: &RoomListItem, right: &RoomListItem) -> Ordering where - F: Fn(&Room, &Room) -> (bool, bool), + F: Fn(&RoomListItem, &RoomListItem) -> (bool, bool), { // We want local latest event to come first. When there is a remote latest event // or no latest event, we don't want to sort them. @@ -46,8 +46,8 @@ where } } -/// Create a new sorter that will sort two [`Room`] by their latest events' -/// state: latest events representing a local event +/// Create a new sorter that will sort two [`RoomListItem`] by their latest +/// events' state: latest events representing a local event /// ([`LatestEventValue::LocalIsSending`] or /// [`LatestEventValue::LocalCannotBeSent`]) come first, and latest event /// representing a remote event ([`LatestEventValue::Remote`]) come last. @@ -56,7 +56,7 @@ where /// [`LatestEventValue::LocalCannotBeSent`]: matrix_sdk_base::latest_event::LatestEventValue::LocalCannotBeSent /// [`LatestEventValue::Remote`]: matrix_sdk_base::latest_event::LatestEventValue::Remote pub fn new_sorter() -> impl Sorter { - let latest_events = |left: &Room, right: &Room| { + let latest_events = |left: &RoomListItem, right: &RoomListItem| { // Be careful. This method is called **a lot** in the context of a sorter. Using // `Room::new_latest_event` would be dramatic as it returns a clone of the // `LatestEventValue`. It's better to use the more specific method diff --git a/crates/matrix-sdk-ui/src/room_list_service/sorters/mod.rs b/crates/matrix-sdk-ui/src/room_list_service/sorters/mod.rs index 0aaf0603f..86233fe5f 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/sorters/mod.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/sorters/mod.rs @@ -26,15 +26,15 @@ pub use lexicographic::new_sorter as new_sorter_lexicographic; pub use name::new_sorter as new_sorter_name; pub use recency::new_sorter as new_sorter_recency; -use super::Room; +use super::RoomListItem; /// A trait “alias” that represents a _sorter_. /// /// A sorter is simply a function that receives two `&Room`s and returns a /// [`Ordering`]. -pub trait Sorter: Fn(&Room, &Room) -> Ordering {} +pub trait Sorter: Fn(&RoomListItem, &RoomListItem) -> Ordering {} -impl Sorter for F where F: Fn(&Room, &Room) -> Ordering {} +impl Sorter for F where F: Fn(&RoomListItem, &RoomListItem) -> Ordering {} /// Type alias for a boxed sorter function. #[cfg(not(target_family = "wasm"))] diff --git a/crates/matrix-sdk-ui/src/room_list_service/sorters/name.rs b/crates/matrix-sdk-ui/src/room_list_service/sorters/name.rs index 7e435f195..3cef2670d 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/sorters/name.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/sorters/name.rs @@ -14,22 +14,25 @@ use std::cmp::Ordering; -use super::{Room, Sorter}; +use super::{RoomListItem, Sorter}; -fn cmp<'a, 'b, F>(names: F, left: &'a Room, right: &'b Room) -> Ordering +fn cmp<'a, 'b, F>(names: F, left: &'a RoomListItem, right: &'b RoomListItem) -> Ordering where - F: Fn(&'a Room, &'b Room) -> (Option<&'a str>, Option<&'b str>), + F: Fn(&'a RoomListItem, &'b RoomListItem) -> (Option<&'a str>, Option<&'b str>), { let (left_name, right_name) = names(left, right); left_name.cmp(&right_name) } -/// Create a new sorter that will sort two [`Room`] by name, i.e. by +/// Create a new sorter that will sort two [`RoomListItem`] by name, i.e. by /// comparing their display names. A lexicographically ordering is applied, i.e. /// "a" < "b". pub fn new_sorter() -> impl Sorter { - fn names<'a, 'b>(left: &'a Room, right: &'b Room) -> (Option<&'a str>, Option<&'b str>) { + fn names<'a, 'b>( + left: &'a RoomListItem, + right: &'b RoomListItem, + ) -> (Option<&'a str>, Option<&'b str>) { (left.cached_display_name.as_deref(), right.cached_display_name.as_deref()) } diff --git a/crates/matrix-sdk-ui/src/room_list_service/sorters/recency.rs b/crates/matrix-sdk-ui/src/room_list_service/sorters/recency.rs index 5ee382a61..3606d8817 100644 --- a/crates/matrix-sdk-ui/src/room_list_service/sorters/recency.rs +++ b/crates/matrix-sdk-ui/src/room_list_service/sorters/recency.rs @@ -14,11 +14,11 @@ use std::cmp::Ordering; -use super::{Room, Sorter}; +use super::{RoomListItem, Sorter}; -fn cmp(ranks: F, left: &Room, right: &Room) -> Ordering +fn cmp(ranks: F, left: &RoomListItem, right: &RoomListItem) -> Ordering where - F: Fn(&Room, &Room) -> (Option, Option), + F: Fn(&RoomListItem, &RoomListItem) -> (Option, Option), { if left.room_id() == right.room_id() { // `left` and `right` are the same room. We are comparing the same @@ -52,8 +52,8 @@ where } } -/// Create a new sorter that will sort two [`Room`] by recency, i.e. by -/// comparing their [`RoomInfo::new_latest_event`]'s recency (timestamp) +/// Create a new sorter that will sort two [`RoomListItem`] by recency, i.e. +/// by comparing their [`RoomInfo::new_latest_event`]'s recency (timestamp) /// if any (i.e. if different from [`LatestEventValue::None`]), or their /// [`RoomInfo::recency_stamp`] value. The `Room` with the newest recency stamp /// comes first, i.e. newest < oldest. @@ -62,7 +62,7 @@ where /// [`RoomInfo::new_latest_event`]: matrix_sdk_base::RoomInfo::new_latest_event /// [`LatestEventValue::None`]: matrix_sdk_base::latest_event::LatestEventValue::None pub fn new_sorter() -> impl Sorter { - let ranks = |left: &Room, right: &Room| extract_rank(left, right); + let ranks = |left: &RoomListItem, right: &RoomListItem| extract_rank(left, right); move |left, right| -> Ordering { cmp(ranks, left, right) } } @@ -80,7 +80,7 @@ type Rank = u64; /// [`RoomInfo::recency_stamp`], but we **must never** mix both. The /// `RoomInfo::recency_stamp` is not a timestamp, while `LatestEventValue` uses /// a timestamp. -fn extract_rank(left: &Room, right: &Room) -> (Option, Option) { +fn extract_rank(left: &RoomListItem, right: &RoomListItem) -> (Option, Option) { // Be careful. This method is called **a lot** in the context of a sorter. Using // `Room::new_latest_event` would be dramatic as it returns a clone of the // `LatestEventValue`. It's better to use the more specific method @@ -165,14 +165,14 @@ mod tests { }) } - fn set_latest_event_value(room: &mut Room, latest_event_value: LatestEventValue) { + fn set_latest_event_value(room: &mut RoomListItem, latest_event_value: LatestEventValue) { let mut room_info = room.clone_info(); room_info.set_new_latest_event(latest_event_value); room.set_room_info(room_info, RoomInfoNotableUpdateReasons::LATEST_EVENT); room.refresh_cached_data(); } - fn set_recency_stamp(room: &mut Room, recency_stamp: RoomRecencyStamp) { + fn set_recency_stamp(room: &mut RoomListItem, recency_stamp: RoomRecencyStamp) { let mut room_info = room.clone_info(); room_info.update_recency_stamp(recency_stamp); room.set_room_info(room_info, RoomInfoNotableUpdateReasons::RECENCY_STAMP); diff --git a/labs/multiverse/src/widgets/room_list.rs b/labs/multiverse/src/widgets/room_list.rs index 74fcb38b6..add66f8c5 100644 --- a/labs/multiverse/src/widgets/room_list.rs +++ b/labs/multiverse/src/widgets/room_list.rs @@ -23,7 +23,7 @@ pub struct ExtraRoomInfo { pub is_dm: Option, } -pub type Rooms = Arc>>; +pub type Rooms = Arc>>; pub type RoomInfos = Arc>>; pub struct RoomList {