diff --git a/bindings/matrix-sdk-ffi/src/api.udl b/bindings/matrix-sdk-ffi/src/api.udl index 03f242154..bdb95afcf 100644 --- a/bindings/matrix-sdk-ffi/src/api.udl +++ b/bindings/matrix-sdk-ffi/src/api.udl @@ -164,7 +164,7 @@ interface Client { [Throws=ClientError] string display_name(); - + [Throws=ClientError] void set_display_name(string name); @@ -179,7 +179,7 @@ interface Client { [Throws=ClientError] void set_account_data(string event_type, string content); - + [Throws=ClientError] string upload_media(string mime_type, sequence content); @@ -295,24 +295,8 @@ interface MediaSource { string url(); }; -[Error] -enum AuthenticationError { - "ClientMissing", - "SessionMissing", - "Generic", -}; - interface AuthenticationService { constructor(string base_path); - - [Throws=AuthenticationError] - void configure_homeserver(string server_name); - - [Throws=AuthenticationError] - Client login(string username, string password, string? initial_device_name, string? device_id); - - [Throws=AuthenticationError] - Client restore_with_access_token(string token, string device_id); }; interface SessionVerificationEmoji {}; diff --git a/bindings/matrix-sdk-ffi/src/authentication_service.rs b/bindings/matrix-sdk-ffi/src/authentication_service.rs index bef5a7f7b..b9687f828 100644 --- a/bindings/matrix-sdk-ffi/src/authentication_service.rs +++ b/bindings/matrix-sdk-ffi/src/authentication_service.rs @@ -14,7 +14,8 @@ pub struct AuthenticationService { homeserver_details: RwLock>>, } -#[derive(Debug, thiserror::Error)] +#[derive(Debug, thiserror::Error, uniffi::Error)] +#[uniffi(flat_error)] pub enum AuthenticationError { #[error("A successful call to use_server must be made first.")] ClientMissing, @@ -56,13 +57,6 @@ impl HomeserverLoginDetails { } } -#[uniffi::export] -impl AuthenticationService { - pub fn homeserver_details(&self) -> Option> { - self.homeserver_details.read().unwrap().clone() - } -} - impl AuthenticationService { /// Creates a new service to authenticate a user with. pub fn new(base_path: String) -> Self { @@ -73,6 +67,32 @@ impl AuthenticationService { } } + /// Get the homeserver login details from a client. + async fn details_from_client( + &self, + client: &Arc, + ) -> Result { + let login_details = join3( + client.async_homeserver(), + client.authentication_issuer(), + client.supports_password_login(), + ) + .await; + + let url = login_details.0; + let authentication_issuer = login_details.1; + let supports_password_login = login_details.2.map_err(AuthenticationError::from)?; + + Ok(HomeserverLoginDetails { url, authentication_issuer, supports_password_login }) + } +} + +#[uniffi::export] +impl AuthenticationService { + pub fn homeserver_details(&self) -> Option> { + self.homeserver_details.read().unwrap().clone() + } + /// Updates the service to authenticate with the homeserver for the /// specified address. pub fn configure_homeserver(&self, server_name: String) -> Result<(), AuthenticationError> { @@ -181,23 +201,4 @@ impl AuthenticationService { client.restore_session_inner(session).map_err(AuthenticationError::from)?; Ok(client) } - - /// Get the homeserver login details from a client. - async fn details_from_client( - &self, - client: &Arc, - ) -> Result { - let login_details = join3( - client.async_homeserver(), - client.authentication_issuer(), - client.supports_password_login(), - ) - .await; - - let url = login_details.0; - let authentication_issuer = login_details.1; - let supports_password_login = login_details.2.map_err(AuthenticationError::from)?; - - Ok(HomeserverLoginDetails { url, authentication_issuer, supports_password_login }) - } } diff --git a/bindings/matrix-sdk-ffi/src/lib.rs b/bindings/matrix-sdk-ffi/src/lib.rs index 144be8c09..84d2ca4b9 100644 --- a/bindings/matrix-sdk-ffi/src/lib.rs +++ b/bindings/matrix-sdk-ffi/src/lib.rs @@ -77,7 +77,9 @@ mod uniffi_types { pub use matrix_sdk::ruma::events::room::{message::RoomMessageEventContent, MediaSource}; pub use crate::{ - authentication_service::{AuthenticationService, HomeserverLoginDetails}, + authentication_service::{ + AuthenticationError, AuthenticationService, HomeserverLoginDetails, + }, client::Client, client_builder::ClientBuilder, room::{Membership, MembershipState, Room, RoomMember},