From eebbb74be7b550a5528ca53940ad66ea0ac482d6 Mon Sep 17 00:00:00 2001 From: Doug Date: Thu, 9 May 2024 10:08:26 +0100 Subject: [PATCH] ffi: Include servers when resolving a room alias. Rename result. --- bindings/matrix-sdk-ffi/src/client.rs | 30 +++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 12bbe6c4a..61a8c8d77 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -43,7 +43,7 @@ use matrix_sdk_ui::notification_client::{ }; use mime::Mime; use ruma::{ - api::client::discovery::discover_homeserver::AuthenticationServerInfo, + api::client::{alias::get_alias, discovery::discover_homeserver::AuthenticationServerInfo}, events::{ ignored_user_list::IgnoredUserListEventContent, room::power_levels::RoomPowerLevelsEventContent, GlobalAccountDataEventType, @@ -734,11 +734,15 @@ impl Client { Ok(()) } - /// Resolves the given room alias to a room id, if possible. - pub async fn resolve_room_alias(&self, room_alias: String) -> Result { + /// Resolves the given room alias to a room ID (and a list of servers), if + /// possible. + pub async fn resolve_room_alias( + &self, + room_alias: String, + ) -> Result { let room_alias = RoomAliasId::parse(&room_alias)?; let response = self.inner.resolve_room_alias(&room_alias).await?; - Ok(response.room_id.to_string()) + Ok(response.into()) } /// Get the preview of a room, to interact with it. @@ -789,6 +793,24 @@ impl From for MatrixNotificationProcessSetup { } } +/// Information about a room, that was resolved from a room alias. +#[derive(uniffi::Record)] +pub struct ResolvedRoomAlias { + /// The room ID that the alias resolved to. + pub room_id: String, + /// A list of servers that can be used to find the room by its room ID. + pub servers: Vec, +} + +impl From for ResolvedRoomAlias { + fn from(value: get_alias::v3::Response) -> Self { + Self { + room_id: value.room_id.to_string(), + servers: value.servers.iter().map(ToString::to_string).collect(), + } + } +} + #[derive(uniffi::Record)] pub struct SearchUsersResults { pub results: Vec,