From 0d87d0f786760e2ef56aa5e15df2f440905fbf35 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 2 Feb 2023 13:27:54 +0100 Subject: [PATCH] feat(sdk): Remove `SlidingSyncView.rooms`. `SlidingSyncView` exposes a `room` field. Problem: It's not updated correctly and leads to error. The canonical way to get a room is by using `SlidingSync::get_room`. This patch thus removes `SlidingSyncView.rooms` entirely. --- crates/matrix-sdk/src/sliding_sync.rs | 29 +++------------------------ 1 file changed, 3 insertions(+), 26 deletions(-) diff --git a/crates/matrix-sdk/src/sliding_sync.rs b/crates/matrix-sdk/src/sliding_sync.rs index bf91446d1..f9fb870ac 100644 --- a/crates/matrix-sdk/src/sliding_sync.rs +++ b/crates/matrix-sdk/src/sliding_sync.rs @@ -1126,15 +1126,14 @@ pub struct SlidingSyncView { /// The state this view is in #[builder(private, default)] pub state: ViewState, + /// The total known number of rooms, #[builder(private, default)] pub rooms_count: RoomsCount, + /// The rooms in order #[builder(private, default)] pub rooms_list: RoomsList, - /// The rooms details - #[builder(private, default)] - pub rooms: RoomsMap, /// The ranges windows of the view #[builder(setter(name = "ranges_raw"), default)] @@ -1675,28 +1674,7 @@ impl SlidingSyncView { self } - /// Return the subset of rooms, starting at offset (default 0) returning - /// count (or to the end) items - pub fn get_rooms( - &self, - offset: Option, - count: Option, - ) -> Vec { - let start = offset.unwrap_or(0); - let rooms = self.rooms.lock_ref(); - let listing = self.rooms_list.lock_ref(); - let count = count.unwrap_or(listing.len() - start); - listing - .iter() - .skip(start) - .filter_map(|id| id.as_room_id()) - .filter_map(|id| rooms.get(id)) - .map(|r| r.inner.clone()) - .take(count) - .collect() - } - - /// Find the current valid position of the room in the vies room_list. + /// Find the current valid position of the room in the view room_list. /// /// Only matches against the current ranges and only against filled items. /// Invalid items are ignore. Return the total position the item was @@ -1799,7 +1777,6 @@ impl SlidingSyncView { { // keep the lock scoped so that the later find_rooms_in_view doesn't deadlock let mut rooms_list = self.rooms_list.lock_mut(); - let _rooms_map = self.rooms.lock_mut(); if !ops.is_empty() { room_ops(&mut rooms_list, ops, ranges)?;