mirror of
https://github.com/matrix-org/matrix-rust-sdk.git
synced 2026-05-14 19:16:02 -04:00
refactor(bindings): Use proc-macro frontend more in sdk-ffi
This commit is contained in:
committed by
Jonas Platte
parent
b3f146c932
commit
eb0c3449fa
@@ -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<u8> 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 {};
|
||||
|
||||
@@ -14,7 +14,8 @@ pub struct AuthenticationService {
|
||||
homeserver_details: RwLock<Option<Arc<HomeserverLoginDetails>>>,
|
||||
}
|
||||
|
||||
#[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<Arc<HomeserverLoginDetails>> {
|
||||
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<Client>,
|
||||
) -> Result<HomeserverLoginDetails, AuthenticationError> {
|
||||
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<Arc<HomeserverLoginDetails>> {
|
||||
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<Client>,
|
||||
) -> Result<HomeserverLoginDetails, AuthenticationError> {
|
||||
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 })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user