Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element specific well-known support #3617

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,13 @@ impl Client {
}
})))
}

/// Allows generic GET requests to be made through the SDKs internal HTTP
/// client
pub async fn get_url(&self, url: String) -> Result<String, ClientError> {
let http_client = self.inner.http_client();
Ok(http_client.get(url).send().await?.text().await?)
}
}

impl Client {
Expand Down Expand Up @@ -499,6 +506,12 @@ impl Client {
Ok(user_id.to_string())
}

/// The server name part of the current user ID
pub fn user_id_server_name(&self) -> Result<String, ClientError> {
let user_id = self.inner.user_id().context("No User ID found")?;
Ok(user_id.server_name().to_string())
}

pub async fn display_name(&self) -> Result<String, ClientError> {
let display_name =
self.inner.account().get_display_name().await?.context("No User ID found")?;
Expand Down
21 changes: 21 additions & 0 deletions bindings/matrix-sdk-ffi/src/element.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use serde::Deserialize;

use crate::ClientError;

/// Well-known settings specific to ElementCall
#[derive(Deserialize, uniffi::Record)]
pub struct ElementCallWellKnown {
widget_url: String,
}

/// Element specific well-known settings
poljar marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Deserialize, uniffi::Record)]
pub struct ElementWellKnown {
call: ElementCallWellKnown,
}

/// Helper function to parse a string into a ElementWellKnown struct
#[uniffi::export]
pub fn make_element_well_known(string: String) -> Result<ElementWellKnown, ClientError> {
serde_json::from_str(&string).map_err(ClientError::new)
}
8 changes: 7 additions & 1 deletion bindings/matrix-sdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::fmt::Display;

use matrix_sdk::{
encryption::CryptoStoreError, event_cache::EventCacheError, oidc::OidcError,
encryption::CryptoStoreError, event_cache::EventCacheError, oidc::OidcError, reqwest,
send_queue::RoomSendQueueError, HttpError, IdParseError,
NotificationSettingsError as SdkNotificationSettingsError, StoreError,
};
Expand All @@ -26,6 +26,12 @@ impl From<anyhow::Error> for ClientError {
}
}

impl From<reqwest::Error> for ClientError {
fn from(e: reqwest::Error) -> Self {
Self::new(e)
}
}

impl From<UnexpectedUniFFICallbackError> for ClientError {
fn from(e: UnexpectedUniFFICallbackError) -> Self {
Self::new(e)
Expand Down
1 change: 1 addition & 0 deletions bindings/matrix-sdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod authentication;
mod chunk_iterator;
mod client;
mod client_builder;
mod element;
mod encryption;
mod error;
mod event;
Expand Down
5 changes: 5 additions & 0 deletions crates/matrix-sdk/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ impl Client {
&self.inner.base_client
}

/// The underlying HTTP client.
pub fn http_client(&self) -> &reqwest::Client {
&self.inner.http_client.inner
}

pub(crate) fn locks(&self) -> &ClientLocks {
&self.inner.locks
}
Expand Down
Loading