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`.
This commit is contained in:
@@ -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<F>(number_of_direct_targets: F, room: &Room, expected_kind: RoomCategory) -> bool
|
||||
fn matches<F>(number_of_direct_targets: F, room: &RoomListItem, expected_kind: RoomCategory) -> bool
|
||||
where
|
||||
F: Fn(&Room) -> Option<DirectTargetsLength>,
|
||||
F: Fn(&RoomListItem) -> Option<DirectTargetsLength>,
|
||||
{
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
|
||||
use matrix_sdk_base::RoomState;
|
||||
|
||||
use super::{super::Room, Filter};
|
||||
use super::{super::RoomListItem, Filter};
|
||||
|
||||
type SuccessorRoomState = RoomState;
|
||||
|
||||
fn matches<F>(state: F, room: &Room) -> bool
|
||||
fn matches<F>(state: F, room: &RoomListItem) -> bool
|
||||
where
|
||||
F: Fn(&Room) -> (RoomState, Option<SuccessorRoomState>),
|
||||
F: Fn(&RoomListItem) -> (RoomState, Option<SuccessorRoomState>),
|
||||
{
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<F>(is_favourite: F, room: &Room) -> bool
|
||||
fn matches<F>(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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
|
||||
use matrix_sdk_base::RoomState;
|
||||
|
||||
use super::{super::Room, Filter};
|
||||
use super::{super::RoomListItem, Filter};
|
||||
|
||||
fn matches<F>(state: F, room: &Room) -> bool
|
||||
fn matches<F>(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) }
|
||||
}
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
|
||||
use matrix_sdk_base::RoomState;
|
||||
|
||||
use super::{super::Room, Filter};
|
||||
use super::{super::RoomListItem, Filter};
|
||||
|
||||
fn matches<F>(state: F, room: &Room) -> bool
|
||||
fn matches<F>(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) }
|
||||
}
|
||||
|
||||
@@ -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<F>(is_low_priority: F, room: &Room) -> bool
|
||||
fn matches<F>(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) }
|
||||
}
|
||||
|
||||
@@ -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<F> Filter for F where F: Fn(&Room) -> bool {}
|
||||
impl<F> 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<const N: usize>(
|
||||
room_ids: [&RoomId; N],
|
||||
client: &Client,
|
||||
server: &MockServer,
|
||||
) -> [Room; N] {
|
||||
) -> [RoomListItem; N] {
|
||||
let mut response_builder = SyncResponseBuilder::default();
|
||||
|
||||
for room_id in room_ids {
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
|
||||
use matrix_sdk_base::RoomState;
|
||||
|
||||
use super::{super::Room, Filter};
|
||||
use super::{super::RoomListItem, Filter};
|
||||
|
||||
fn matches<F>(state: F, room: &Room) -> bool
|
||||
fn matches<F>(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) }
|
||||
}
|
||||
|
||||
@@ -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<F>(is_space: F, room: &Room) -> bool
|
||||
fn matches<F>(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 <https://spec.matrix.org/latest/client-server-api/#spaces>
|
||||
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) }
|
||||
}
|
||||
|
||||
@@ -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<F>(read_receipts_and_unread: F, room: &Room) -> bool
|
||||
fn matches<F>(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));
|
||||
}
|
||||
|
||||
@@ -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<matrix_sdk::Room, Error> {
|
||||
/// Get a [`Room`] if it exists.
|
||||
pub fn room(&self, room_id: &RoomId) -> Result<Room, Error> {
|
||||
self.client.get_room(room_id).ok_or_else(|| Error::RoomNotFound(room_id.to_owned()))
|
||||
}
|
||||
|
||||
|
||||
@@ -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<matrix_sdk::Room>, impl Stream<Item = Vec<VectorDiff<matrix_sdk::Room>>> + '_)
|
||||
{
|
||||
fn entries(&self) -> (Vector<Room>, impl Stream<Item = Vec<VectorDiff<Room>>> + '_) {
|
||||
self.client.rooms_stream()
|
||||
}
|
||||
|
||||
@@ -142,7 +139,8 @@ impl RoomList {
|
||||
pub fn entries_with_dynamic_adapters(
|
||||
&self,
|
||||
page_size: usize,
|
||||
) -> (impl Stream<Item = Vec<VectorDiff<Room>>> + '_, RoomListDynamicEntriesController) {
|
||||
) -> (impl Stream<Item = Vec<VectorDiff<RoomListItem>>> + '_, 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::<Vector<Room>>();
|
||||
let values = raw_values.into_iter().map(Into::into).collect::<Vector<RoomListItem>>();
|
||||
|
||||
// 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<Room>,
|
||||
raw_stream: impl Stream<Item = Vec<VectorDiff<matrix_sdk::Room>>>,
|
||||
mut current_values: Vector<RoomListItem>,
|
||||
raw_stream: impl Stream<Item = Vec<VectorDiff<Room>>>,
|
||||
mut room_info_notable_update_receiver: broadcast::Receiver<RoomInfoNotableUpdate>,
|
||||
) -> impl Stream<Item = Vec<VectorDiff<Room>>> {
|
||||
) -> impl Stream<Item = Vec<VectorDiff<RoomListItem>>> {
|
||||
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::<Vec<_>>();
|
||||
let diffs = diffs.into_iter().map(|diff| diff.map(RoomListItem::from)).collect::<Vec<_>>();
|
||||
|
||||
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<MilliSecondsSinceUnixEpoch>,
|
||||
|
||||
/// 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<RoomRecencyStamp>,
|
||||
|
||||
/// 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<String>,
|
||||
|
||||
/// 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<matrix_sdk::Room> for Room {
|
||||
fn from(inner: matrix_sdk::Room) -> Self {
|
||||
impl From<Room> 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<matrix_sdk::Room> 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
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use super::{Room, Sorter};
|
||||
use super::{RoomListItem, Sorter};
|
||||
|
||||
fn cmp<F>(are_latest_events_locals: F, left: &Room, right: &Room) -> Ordering
|
||||
fn cmp<F>(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
|
||||
|
||||
@@ -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<F> Sorter for F where F: Fn(&Room, &Room) -> Ordering {}
|
||||
impl<F> Sorter for F where F: Fn(&RoomListItem, &RoomListItem) -> Ordering {}
|
||||
|
||||
/// Type alias for a boxed sorter function.
|
||||
#[cfg(not(target_family = "wasm"))]
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
|
||||
use std::cmp::Ordering;
|
||||
|
||||
use super::{Room, Sorter};
|
||||
use super::{RoomListItem, Sorter};
|
||||
|
||||
fn cmp<F>(ranks: F, left: &Room, right: &Room) -> Ordering
|
||||
fn cmp<F>(ranks: F, left: &RoomListItem, right: &RoomListItem) -> Ordering
|
||||
where
|
||||
F: Fn(&Room, &Room) -> (Option<Rank>, Option<Rank>),
|
||||
F: Fn(&RoomListItem, &RoomListItem) -> (Option<Rank>, Option<Rank>),
|
||||
{
|
||||
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<Rank>, Option<Rank>) {
|
||||
fn extract_rank(left: &RoomListItem, right: &RoomListItem) -> (Option<Rank>, Option<Rank>) {
|
||||
// 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);
|
||||
|
||||
@@ -23,7 +23,7 @@ pub struct ExtraRoomInfo {
|
||||
pub is_dm: Option<bool>,
|
||||
}
|
||||
|
||||
pub type Rooms = Arc<Mutex<Vector<matrix_sdk_ui::room_list_service::Room>>>;
|
||||
pub type Rooms = Arc<Mutex<Vector<matrix_sdk_ui::room_list_service::RoomListItem>>>;
|
||||
pub type RoomInfos = Arc<Mutex<HashMap<OwnedRoomId, ExtraRoomInfo>>>;
|
||||
|
||||
pub struct RoomList {
|
||||
|
||||
Reference in New Issue
Block a user