From e6dc203c4ddb1e452b9aebc40f5bc8466dcf148c Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Mon, 19 May 2025 10:22:46 +0300 Subject: [PATCH] change(ffi): pass the client utd manager down into the timeline builder --- bindings/matrix-sdk-ffi/src/client.rs | 27 +++++++++++++-------- bindings/matrix-sdk-ffi/src/notification.rs | 2 +- bindings/matrix-sdk-ffi/src/room.rs | 16 +++++++++--- 3 files changed, 30 insertions(+), 15 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 7c63bf939..5ef1c0c87 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -221,7 +221,7 @@ impl From for TransmissionProgress { pub struct Client { pub(crate) inner: AsyncRuntimeDropped, delegate: RwLock>>, - utd_hook_manager: Option>, + utd_hook: Option>, session_verification_controller: Arc>>, } @@ -267,7 +267,7 @@ impl Client { let mut client = Client { inner: AsyncRuntimeDropped::new(sdk_client.clone()), delegate: RwLock::new(None), - utd_hook_manager: None, + utd_hook: None, session_verification_controller, }; @@ -319,7 +319,7 @@ impl Client { // because the UTD hook failed to load its data. } - client.utd_hook_manager = Some(Arc::new(utd_hook)); + client.utd_hook = Some(Arc::new(utd_hook)); } Ok(client) @@ -1053,7 +1053,11 @@ impl Client { } pub fn rooms(&self) -> Vec> { - self.inner.rooms().into_iter().map(|room| Arc::new(Room::new(room))).collect() + self.inner + .rooms() + .into_iter() + .map(|room| Arc::new(Room::new(room, self.utd_hook.clone()))) + .collect() } /// Get a room by its ID. @@ -1070,14 +1074,14 @@ impl Client { pub fn get_room(&self, room_id: String) -> Result>, ClientError> { let room_id = RoomId::parse(room_id)?; let sdk_room = self.inner.get_room(&room_id); - let room = sdk_room.map(|room| Arc::new(Room::new(room))); + let room = sdk_room.map(|room| Arc::new(Room::new(room, self.utd_hook.clone()))); Ok(room) } pub fn get_dm_room(&self, user_id: String) -> Result>, ClientError> { let user_id = UserId::parse(user_id)?; let sdk_room = self.inner.get_dm_room(&user_id); - let dm = sdk_room.map(|room| Arc::new(Room::new(room))); + let dm = sdk_room.map(|room| Arc::new(Room::new(room, self.utd_hook.clone()))); Ok(dm) } @@ -1184,7 +1188,7 @@ impl Client { pub async fn join_room_by_id(&self, room_id: String) -> Result, ClientError> { let room_id = RoomId::parse(room_id)?; let room = self.inner.join_room_by_id(room_id.as_ref()).await?; - Ok(Arc::new(Room::new(room))) + Ok(Arc::new(Room::new(room, self.utd_hook.clone()))) } /// Join a room by its ID or alias. @@ -1205,7 +1209,7 @@ impl Client { .collect::, _>>()?; let room = self.inner.join_room_by_id_or_alias(room_id.as_ref(), server_names.as_ref()).await?; - Ok(Arc::new(Room::new(room))) + Ok(Arc::new(Room::new(room, self.utd_hook.clone()))) } /// Knock on a room to join it using its ID or alias. @@ -1219,7 +1223,7 @@ impl Client { let server_names = server_names.iter().map(ServerName::parse).collect::, _>>()?; let room = self.inner.knock(room_id, reason, server_names).await?; - Ok(Arc::new(Room::new(room))) + Ok(Arc::new(Room::new(room, self.utd_hook.clone()))) } pub async fn get_recently_visited_rooms(&self) -> Result, ClientError> { @@ -1313,7 +1317,10 @@ impl Client { /// or an externally set timeout happens.** pub async fn await_room_remote_echo(&self, room_id: String) -> Result, ClientError> { let room_id = RoomId::parse(room_id)?; - Ok(Arc::new(Room::new(self.inner.await_room_remote_echo(&room_id).await))) + Ok(Arc::new(Room::new( + self.inner.await_room_remote_echo(&room_id).await, + self.utd_hook.clone(), + ))) } /// Lets the user know whether this is an `m.login.password` based diff --git a/bindings/matrix-sdk-ffi/src/notification.rs b/bindings/matrix-sdk-ffi/src/notification.rs index d60870b88..0f9b78f64 100644 --- a/bindings/matrix-sdk-ffi/src/notification.rs +++ b/bindings/matrix-sdk-ffi/src/notification.rs @@ -108,7 +108,7 @@ impl NotificationClient { pub fn get_room(&self, room_id: String) -> Result>, ClientError> { let room_id = RoomId::parse(room_id)?; let sdk_room = self.inner.get_room(&room_id); - let room = sdk_room.map(|room| Arc::new(Room::new(room))); + let room = sdk_room.map(|room| Arc::new(Room::new(room, None))); Ok(room) } diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index d0f40f596..440ab95c7 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -12,7 +12,10 @@ use matrix_sdk::{ ComposerDraft as SdkComposerDraft, ComposerDraftType as SdkComposerDraftType, EncryptionState, RoomHero as SdkRoomHero, RoomMemberships, RoomState, }; -use matrix_sdk_ui::timeline::{default_event_filter, RoomExt, TimelineBuilder}; +use matrix_sdk_ui::{ + timeline::{default_event_filter, RoomExt, TimelineBuilder}, + unable_to_decrypt_hook::UtdHookManager, +}; use mime::Mime; use ruma::{ assign, @@ -75,16 +78,17 @@ pub(crate) type TimelineLock = Arc>>>; #[derive(uniffi::Object)] pub struct Room { pub(super) inner: SdkRoom, + utd_hook: Option>, timeline: TimelineLock, } impl Room { - pub(crate) fn new(inner: SdkRoom) -> Self { - Room { inner, timeline: Default::default() } + pub(crate) fn new(inner: SdkRoom, utd_hook: Option>) -> Self { + Room { inner, timeline: Default::default(), utd_hook } } pub(crate) fn with_timeline(inner: SdkRoom, timeline: TimelineLock) -> Self { - Room { inner, timeline } + Room { inner, timeline, utd_hook: None } } } @@ -233,6 +237,10 @@ impl Room { builder = builder.with_internal_id_prefix(internal_id_prefix); } + if let Some(utd_hook) = self.utd_hook.clone() { + builder = builder.with_unable_to_decrypt_hook(utd_hook); + } + let timeline = builder.build().await?; Ok(Timeline::new(timeline))