Skip to content
Open
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
5 changes: 3 additions & 2 deletions bindings/matrix-sdk-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ crate-type = [
]

[features]
default = ["bundled-sqlite", "unstable-msc4274", "experimental-element-recent-emojis"]
default = ["unstable-msc4274", "experimental-element-recent-emojis"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary? Can't you use --no-default-features to get the feature set you'd want/need on Wasm?

Therefor we probably
shouldn't have it as the default since indexeddb support was added.

Why not? The defaults are here to serve the most common use-case. Having only the memory store by default seems like a worse situation.

The matrix-sdk crate also enables SQLite support by default, even though it ~always supported IndexedDB.

# Use SQLite for the session storage.
sqlite = ["matrix-sdk/sqlite"]
# Use an embedded version of SQLite.
Expand Down Expand Up @@ -89,7 +89,8 @@ oauth2.workspace = true
[target.'cfg(target_family = "wasm")'.dependencies]
console_error_panic_hook = "0.1.7"
tokio = { workspace = true, features = ["sync", "macros"] }
uniffi.workspace = true
uniffi = { workspace = true, features = ["wasm-unstable-single-threaded"] }
futures-executor.workspace = true

[target.'cfg(not(target_family = "wasm"))'.dependencies]
async-compat.workspace = true
Expand Down
121 changes: 78 additions & 43 deletions bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,6 @@ impl Client {
}
}

#[cfg(not(target_family = "wasm"))]
#[matrix_sdk_ffi_macros::export]
impl Client {
/// Retrieves a media file from the media source
Expand All @@ -942,22 +941,54 @@ impl Client {
use_cache: bool,
temp_dir: Option<String>,
) -> Result<Arc<MediaFileHandle>, ClientError> {
let source = (*media_source).clone();
let mime_type: mime::Mime = mime_type.parse()?;
#[cfg(not(target_family = "wasm"))]
{
let source = (*media_source).clone();
let mime_type: mime::Mime = mime_type.parse()?;

let handle = self
.inner
.media()
.get_media_file(
&MediaRequestParameters { source: source.media_source, format: MediaFormat::File },
filename,
&mime_type,
use_cache,
temp_dir,
)
.await?;
let handle = self
.inner
.media()
.get_media_file(
&MediaRequestParameters {
source: source.media_source,
format: MediaFormat::File,
},
filename,
&mime_type,
use_cache,
temp_dir,
)
.await?;
Comment on lines +949 to +962
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment explaining why this doesn't work would be nice.

I guess it's because of the usage of the temp dir.


Ok(Arc::new(MediaFileHandle::new(handle)))
}

Ok(Arc::new(MediaFileHandle::new(handle)))
#[cfg(target_family = "wasm")]
Err(ClientError::Generic {
msg: "get_media_file is not supported on wasm platforms".to_owned(),
details: None,
})
}

pub async fn set_display_name(&self, name: String) -> Result<(), ClientError> {
#[cfg(not(target_family = "wasm"))]
{
self.inner
.account()
.set_display_name(Some(name.as_str()))
.await
.context("Unable to set display name")?;
Ok(())
}

#[cfg(target_family = "wasm")]
{
Err(ClientError::Generic {
msg: "set_display_name is not supported on wasm platforms".to_owned(),
details: None,
})
}
}
}

Expand Down Expand Up @@ -1093,15 +1124,6 @@ impl Client {
Ok(display_name)
}

pub async fn set_display_name(&self, name: String) -> Result<(), ClientError> {
self.inner
.account()
.set_display_name(Some(name.as_str()))
.await
.context("Unable to set display name")?;
Ok(())
}

pub async fn upload_avatar(&self, mime_type: String, data: Vec<u8>) -> Result<(), ClientError> {
let mime: Mime = mime_type.parse()?;
self.inner.account().upload_avatar(&mime, data).await?;
Expand Down Expand Up @@ -2453,25 +2475,25 @@ fn gen_transaction_id() -> String {

/// A file handle that takes ownership of a media file on disk. When the handle
/// is dropped, the file will be removed from the disk.
#[cfg(not(target_family = "wasm"))]
#[derive(uniffi::Object)]
pub struct MediaFileHandle {
#[cfg(not(target_family = "wasm"))]
inner: std::sync::RwLock<Option<SdkMediaFileHandle>>,
}

#[cfg(not(target_family = "wasm"))]
impl MediaFileHandle {
#[cfg(not(target_family = "wasm"))]
fn new(handle: SdkMediaFileHandle) -> Self {
Self { inner: std::sync::RwLock::new(Some(handle)) }
}
}

#[cfg(not(target_family = "wasm"))]
#[matrix_sdk_ffi_macros::export]
impl MediaFileHandle {
/// Get the media file's path.
pub fn path(&self) -> Result<String, ClientError> {
Ok(self
#[cfg(not(target_family = "wasm"))]
return Ok(self
.inner
.read()
.unwrap()
Expand All @@ -2480,24 +2502,37 @@ impl MediaFileHandle {
.path()
.to_str()
.unwrap()
.to_owned())
.to_owned());
#[cfg(target_family = "wasm")]
Err(ClientError::Generic {
msg: "MediaFileHandle.path() is not supported on WASM targets".to_string(),
details: None,
})
}

pub fn persist(&self, path: String) -> Result<bool, ClientError> {
let mut guard = self.inner.write().unwrap();
Ok(
match guard
.take()
.context("MediaFileHandle was already persisted")?
.persist(path.as_ref())
{
Ok(_) => true,
Err(e) => {
*guard = Some(e.file);
false
}
},
)
#[cfg(not(target_family = "wasm"))]
{
let mut guard = self.inner.write().unwrap();
Ok(
match guard
.take()
.context("MediaFileHandle was already persisted")?
.persist(path.as_ref())
{
Ok(_) => true,
Err(e) => {
*guard = Some(e.file);
false
}
},
)
}
#[cfg(target_family = "wasm")]
Err(ClientError::Generic {
msg: "MediaFileHandle.persist() is not supported on WASM targets".to_string(),
details: None,
})
}
}

Expand Down
32 changes: 26 additions & 6 deletions bindings/matrix-sdk-ffi/src/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,20 @@ impl ClientBuilder {
system_is_memory_constrained: false,
username: None,
homeserver_cfg: None,
#[cfg(not(target_family = "wasm"))]
user_agent: None,
sliding_sync_version_builder: SlidingSyncVersionBuilder::None,
#[cfg(not(target_family = "wasm"))]
proxy: None,
#[cfg(not(target_family = "wasm"))]
disable_ssl_verification: false,
disable_automatic_token_refresh: false,
cross_process_store_locks_holder_name: None,
enable_oidc_refresh_lock: false,
session_delegate: None,
#[cfg(not(target_family = "wasm"))]
additional_root_certificates: Default::default(),
#[cfg(not(target_family = "wasm"))]
disable_built_in_root_certificates: false,
encryption_settings: EncryptionSettings {
auto_enable_cross_signing: false,
Expand Down Expand Up @@ -559,18 +564,23 @@ impl ClientBuilder {
}
}

#[cfg(not(target_family = "wasm"))]
#[matrix_sdk_ffi_macros::export]
impl ClientBuilder {
pub fn proxy(self: Arc<Self>, url: String) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.proxy = Some(url);
#[cfg(not(target_family = "wasm"))]
{
builder.proxy = Some(url);
}
Arc::new(builder)
}

pub fn disable_ssl_verification(self: Arc<Self>) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.disable_ssl_verification = true;
#[cfg(not(target_family = "wasm"))]
{
builder.disable_ssl_verification = true;
}
Arc::new(builder)
}

Expand All @@ -579,7 +589,11 @@ impl ClientBuilder {
certificates: Vec<CertificateBytes>,
) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.additional_root_certificates = certificates;

#[cfg(not(target_family = "wasm"))]
{
builder.additional_root_certificates = certificates;
}

Arc::new(builder)
}
Expand All @@ -589,13 +603,19 @@ impl ClientBuilder {
/// [`add_root_certificates`][ClientBuilder::add_root_certificates].
pub fn disable_built_in_root_certificates(self: Arc<Self>) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.disable_built_in_root_certificates = true;
#[cfg(not(target_family = "wasm"))]
{
builder.disable_built_in_root_certificates = true;
}
Arc::new(builder)
}

pub fn user_agent(self: Arc<Self>, user_agent: String) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.user_agent = Some(user_agent);
#[cfg(not(target_family = "wasm"))]
{
builder.user_agent = Some(user_agent);
}
Arc::new(builder)
}
}
Expand Down
Loading