mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-04 14:04:40 -04:00
Revert "Revert "chore(ui,ffi): Remove the RoomList::entries method.""
This reverts commit af390328b5.
This commit is contained in:
@@ -182,33 +182,6 @@ impl RoomList {
|
||||
})
|
||||
}
|
||||
|
||||
fn entries(&self, listener: Box<dyn RoomListEntriesListener>) -> Arc<TaskHandle> {
|
||||
let this = self.inner.clone();
|
||||
let utd_hook = self.room_list_service.utd_hook.clone();
|
||||
|
||||
Arc::new(TaskHandle::new(RUNTIME.spawn(async move {
|
||||
let (entries, entries_stream) = this.entries();
|
||||
|
||||
pin_mut!(entries_stream);
|
||||
|
||||
listener.on_update(vec![RoomListEntriesUpdate::Append {
|
||||
values: entries
|
||||
.into_iter()
|
||||
.map(|room| Arc::new(RoomListItem::from(room, utd_hook.clone())))
|
||||
.collect(),
|
||||
}]);
|
||||
|
||||
while let Some(diffs) = entries_stream.next().await {
|
||||
listener.on_update(
|
||||
diffs
|
||||
.into_iter()
|
||||
.map(|diff| RoomListEntriesUpdate::from(diff, utd_hook.clone()))
|
||||
.collect(),
|
||||
);
|
||||
}
|
||||
})))
|
||||
}
|
||||
|
||||
fn entries_with_dynamic_adapters(
|
||||
self: Arc<Self>,
|
||||
page_size: u32,
|
||||
|
||||
@@ -44,9 +44,9 @@
|
||||
//! fluid user experience for a Matrix client.
|
||||
//!
|
||||
//! [`RoomListService::all_rooms`] provides a way to get a [`RoomList`] for all
|
||||
//! the rooms. From that, calling [`RoomList::entries`] provides a way to get a
|
||||
//! stream of room list entry. This stream can be filtered, and the filter can
|
||||
//! be changed over time.
|
||||
//! the rooms. From that, calling [`RoomList::entries_with_dynamic_adapters`]
|
||||
//! provides a way to get a stream of rooms. This stream is sorted, can be
|
||||
//! filtered, and the filter can be changed over time.
|
||||
//!
|
||||
//! [`RoomListService::state`] provides a way to get a stream of the state
|
||||
//! machine's state, which can be pretty helpful for the client app.
|
||||
|
||||
@@ -118,8 +118,8 @@ impl RoomList {
|
||||
self.loading_state.subscribe()
|
||||
}
|
||||
|
||||
/// Get all previous rooms, in addition to a [`Stream`] to rooms' updates.
|
||||
pub fn entries(&self) -> (Vector<Room>, impl Stream<Item = Vec<VectorDiff<Room>>> + '_) {
|
||||
/// Get a stream of rooms.
|
||||
fn entries(&self) -> (Vector<Room>, impl Stream<Item = Vec<VectorDiff<Room>>> + '_) {
|
||||
let (rooms, stream) = self.client.rooms_stream();
|
||||
|
||||
let map_room = |room| Room::new(room, &self.sliding_sync);
|
||||
@@ -130,9 +130,11 @@ impl RoomList {
|
||||
)
|
||||
}
|
||||
|
||||
/// Similar to [`Self::entries`] except that it's possible to provide a
|
||||
/// filter that will filter out room list entries, and that it's also
|
||||
/// possible to “paginate” over the entries by `page_size`.
|
||||
/// Get a configurable stream of rooms.
|
||||
///
|
||||
/// It's possible to provide a filter that will filter out room list
|
||||
/// entries, and that it's also possible to “paginate” over the entries by
|
||||
/// `page_size`. The rooms are also sorted.
|
||||
///
|
||||
/// The returned stream will only start yielding diffs once a filter is set
|
||||
/// through the returned [`RoomListDynamicEntriesController`]. For every
|
||||
|
||||
@@ -1196,98 +1196,6 @@ async fn test_loading_states() -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_entries_stream() -> Result<(), Error> {
|
||||
let (_, server, room_list) = new_room_list_service().await?;
|
||||
|
||||
let sync = room_list.sync();
|
||||
pin_mut!(sync);
|
||||
|
||||
let all_rooms = room_list.all_rooms().await?;
|
||||
|
||||
let (previous_entries, entries_stream) = all_rooms.entries();
|
||||
pin_mut!(entries_stream);
|
||||
|
||||
sync_then_assert_request_and_fake_response! {
|
||||
[server, room_list, sync]
|
||||
states = Init => SettingUp,
|
||||
assert request >= {
|
||||
"lists": {
|
||||
ALL_ROOMS: {
|
||||
"ranges": [[0, 19]],
|
||||
"timeline_limit": 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
respond with = {
|
||||
"pos": "0",
|
||||
"lists": {
|
||||
ALL_ROOMS: {
|
||||
"count": 10,
|
||||
},
|
||||
},
|
||||
"rooms": {
|
||||
"!r0:bar.org": {
|
||||
"initial": true,
|
||||
"timeline": [],
|
||||
},
|
||||
"!r1:bar.org": {
|
||||
"initial": true,
|
||||
"timeline": [],
|
||||
},
|
||||
"!r2:bar.org": {
|
||||
"initial": true,
|
||||
"timeline": [],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
assert!(previous_entries.is_empty());
|
||||
assert_entries_batch! {
|
||||
[entries_stream]
|
||||
push back [ "!r0:bar.org" ];
|
||||
push back [ "!r1:bar.org" ];
|
||||
push back [ "!r2:bar.org" ];
|
||||
end;
|
||||
};
|
||||
|
||||
sync_then_assert_request_and_fake_response! {
|
||||
[server, room_list, sync]
|
||||
states = SettingUp => Running,
|
||||
assert request >= {
|
||||
"lists": {
|
||||
ALL_ROOMS: {
|
||||
"ranges": [[0, 9]],
|
||||
"timeline_limit": 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
respond with = {
|
||||
"pos": "1",
|
||||
"lists": {
|
||||
ALL_ROOMS: {
|
||||
"count": 9,
|
||||
},
|
||||
},
|
||||
"rooms": {
|
||||
"!r3:bar.org": {
|
||||
"initial": true,
|
||||
"timeline": [],
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
assert_entries_batch! {
|
||||
[entries_stream]
|
||||
push back [ "!r3:bar.org" ];
|
||||
end;
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[async_test]
|
||||
async fn test_dynamic_entries_stream() -> Result<(), Error> {
|
||||
let (client, server, room_list) = new_room_list_service().await?;
|
||||
|
||||
Reference in New Issue
Block a user