From 40602e7bba228166facf2e3cec630cf04f84e86d Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Wed, 21 Jun 2023 17:11:26 +0200 Subject: [PATCH] chore(ffi): Update according to previous commits. --- bindings/matrix-sdk-ffi/src/room_list.rs | 109 +++++++++-------------- 1 file changed, 43 insertions(+), 66 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/room_list.rs b/bindings/matrix-sdk-ffi/src/room_list.rs index ba3b99497..5248c434b 100644 --- a/bindings/matrix-sdk-ffi/src/room_list.rs +++ b/bindings/matrix-sdk-ffi/src/room_list.rs @@ -20,8 +20,8 @@ use crate::{ #[uniffi::export] impl Client { /// Get a new `RoomList` instance. - pub fn room_list(&self) -> Result, RoomListError> { - Ok(Arc::new(RoomList { + pub fn room_list(&self) -> Result, RoomListError> { + Ok(Arc::new(RoomListService { inner: Arc::new( RUNTIME .block_on(async { @@ -83,12 +83,12 @@ impl From for matrix_sdk_ui::room_list::Input { } #[derive(uniffi::Object)] -pub struct RoomList { +pub struct RoomListService { inner: Arc, } #[uniffi::export] -impl RoomList { +impl RoomListService { fn sync(&self) { let this = self.inner.clone(); @@ -112,7 +112,7 @@ impl RoomList { matches!(self.inner.state().get(), State::SettingUp | State::Running) } - fn state(&self, listener: Box) -> Arc { + fn state(&self, listener: Box) -> Arc { let state_stream = self.inner.state(); Arc::new(TaskHandle::new(RUNTIME.spawn(async move { @@ -124,59 +124,16 @@ impl RoomList { }))) } - async fn entries( - &self, - listener: Box, - ) -> Result { - let (entries, entries_stream) = self.inner.entries().await.map_err(RoomListError::from)?; - - Ok(RoomListEntriesResult { - entries: entries.into_iter().map(Into::into).collect(), - entries_stream: Arc::new(TaskHandle::new(RUNTIME.spawn(async move { - pin_mut!(entries_stream); - - while let Some(diff) = entries_stream.next().await { - listener.on_update(diff.into()); - } - }))), - }) + async fn all_rooms(&self) -> Result, RoomListError> { + Ok(Arc::new(RoomList { + inner: Arc::new(self.inner.all_rooms().await.map_err(RoomListError::from)?), + })) } - async fn entries_loading_state( - &self, - listener: Box, - ) -> Result { - let (entries_loading_state, entries_loading_state_stream) = - self.inner.entries_loading_state().await.map_err(RoomListError::from)?; - - Ok(RoomListEntriesLoadingStateResult { - entries_loading_state, - entries_loading_state_stream: Arc::new(TaskHandle::new(RUNTIME.spawn(async move { - pin_mut!(entries_loading_state_stream); - - while let Some(loading_state) = entries_loading_state_stream.next().await { - listener.did_receive_update(loading_state); - } - }))), - }) - } - - async fn invites( - &self, - listener: Box, - ) -> Result { - let (entries, entries_stream) = self.inner.invites().await.map_err(RoomListError::from)?; - - Ok(RoomListEntriesResult { - entries: entries.into_iter().map(Into::into).collect(), - entries_stream: Arc::new(TaskHandle::new(RUNTIME.spawn(async move { - pin_mut!(entries_stream); - - while let Some(diff) = entries_stream.next().await { - listener.on_update(diff.into()); - } - }))), - }) + async fn invites(&self) -> Result, RoomListError> { + Ok(Arc::new(RoomList { + inner: Arc::new(self.inner.invites().await.map_err(RoomListError::from)?), + })) } async fn apply_input(&self, input: RoomListInput) -> Result<(), RoomListError> { @@ -192,20 +149,40 @@ impl RoomList { } } +#[derive(uniffi::Object)] +pub struct RoomList { + inner: Arc, +} + +#[uniffi::export] +impl RoomList { + fn entries( + &self, + listener: Box, + ) -> Result { + let (entries, entries_stream) = self.inner.entries(); + + Ok(RoomListEntriesResult { + entries: entries.into_iter().map(Into::into).collect(), + entries_stream: Arc::new(TaskHandle::new(RUNTIME.spawn(async move { + pin_mut!(entries_stream); + + while let Some(diff) = entries_stream.next().await { + listener.on_update(diff.into()); + } + }))), + }) + } +} + #[derive(uniffi::Record)] pub struct RoomListEntriesResult { pub entries: Vec, pub entries_stream: Arc, } -#[derive(uniffi::Record)] -pub struct RoomListEntriesLoadingStateResult { - pub entries_loading_state: SlidingSyncListLoadingState, - pub entries_loading_state_stream: Arc, -} - #[derive(uniffi::Enum)] -pub enum RoomListState { +pub enum RoomListServiceState { Init, SettingUp, Running, @@ -213,7 +190,7 @@ pub enum RoomListState { Terminated, } -impl From for RoomListState { +impl From for RoomListServiceState { fn from(value: matrix_sdk_ui::room_list::State) -> Self { use matrix_sdk_ui::room_list::State::*; @@ -228,8 +205,8 @@ impl From for RoomListState { } #[uniffi::export(callback_interface)] -pub trait RoomListStateListener: Send + Sync + Debug { - fn on_update(&self, state: RoomListState); +pub trait RoomListServiceStateListener: Send + Sync + Debug { + fn on_update(&self, state: RoomListServiceState); } #[derive(uniffi::Enum)]