From ea9a85395aa2268f8ae5666921a35cd73ff2aa79 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 15 Jun 2023 11:11:48 +0200 Subject: [PATCH 1/2] chore(ui): Add missing trailing commas. --- crates/matrix-sdk-ui/tests/integration/room_list.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/matrix-sdk-ui/tests/integration/room_list.rs b/crates/matrix-sdk-ui/tests/integration/room_list.rs index b610e18712e..0422aaa6cd6 100644 --- a/crates/matrix-sdk-ui/tests/integration/room_list.rs +++ b/crates/matrix-sdk-ui/tests/integration/room_list.rs @@ -1573,8 +1573,8 @@ async fn test_input_viewport() -> Result<(), Error> { VISIBLE_ROOMS: { "ranges": [], "timeline_limit": 20, - } - } + }, + }, }, respond with = { "pos": "1", @@ -1596,8 +1596,8 @@ async fn test_input_viewport() -> Result<(), Error> { VISIBLE_ROOMS: { "ranges": [[10, 15], [20, 25]], "timeline_limit": 20, - } - } + }, + }, }, respond with = { "pos": "1", From 59565657fab3ca3008e9800cc33cf3f77b069527 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Thu, 15 Jun 2023 11:12:17 +0200 Subject: [PATCH 2/2] feat(ffi): Implement `RoomList::apply_input`. This patch implements `RoomList::apply_input`. Usage example: ```rust room_list.apply_input(RoomListInput::Viewport { ranges: vec![RoomListRange { start: 10, end_inclusive: 20 }]}).await?; ``` --- bindings/matrix-sdk-ffi/src/api.udl | 10 ++++++++++ bindings/matrix-sdk-ffi/src/room_list.rs | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/bindings/matrix-sdk-ffi/src/api.udl b/bindings/matrix-sdk-ffi/src/api.udl index 1d1f9b74ee9..22b0566b125 100644 --- a/bindings/matrix-sdk-ffi/src/api.udl +++ b/bindings/matrix-sdk-ffi/src/api.udl @@ -198,3 +198,13 @@ interface RoomListEntriesUpdate { callback interface RoomListEntriesListener { void on_update(RoomListEntriesUpdate room_entries_update); }; + +[Enum] +interface RoomListInput { + Viewport(sequence ranges); +}; + +dictionary RoomListRange { + u32 start; + u32 end_inclusive; +}; diff --git a/bindings/matrix-sdk-ffi/src/room_list.rs b/bindings/matrix-sdk-ffi/src/room_list.rs index 213c49f4942..bfa3abffbf4 100644 --- a/bindings/matrix-sdk-ffi/src/room_list.rs +++ b/bindings/matrix-sdk-ffi/src/room_list.rs @@ -54,6 +54,25 @@ impl From for RoomListError { } } +pub struct RoomListRange { + pub start: u32, + pub end_inclusive: u32, +} + +pub enum RoomListInput { + Viewport { ranges: Vec }, +} + +impl From for matrix_sdk_ui::room_list::Input { + fn from(value: RoomListInput) -> Self { + match value { + RoomListInput::Viewport { ranges } => Self::Viewport( + ranges.iter().map(|range| range.start..=range.end_inclusive).collect(), + ), + } + } +} + #[derive(uniffi::Object)] pub struct RoomList { inner: Arc, @@ -104,6 +123,10 @@ impl RoomList { }) } + async fn apply_input(&self, input: RoomListInput) -> Result<(), RoomListError> { + self.inner.apply_input(input.into()).await.map_err(Into::into) + } + fn room(&self, room_id: String) -> Result, RoomListError> { let room_id = <&RoomId>::try_from(room_id.as_str()).map_err(RoomListError::from)?;