diff --git a/bindings/matrix-sdk-ffi/Cargo.toml b/bindings/matrix-sdk-ffi/Cargo.toml index 35cfb2c10..0e09e2434 100644 --- a/bindings/matrix-sdk-ffi/Cargo.toml +++ b/bindings/matrix-sdk-ffi/Cargo.toml @@ -60,7 +60,7 @@ matrix-sdk = { workspace = true, features = [ matrix-sdk-base.workspace = true matrix-sdk-common.workspace = true matrix-sdk-ffi-macros.workspace = true -matrix-sdk-ui = { workspace = true, features = ["uniffi"] } +matrix-sdk-ui = { workspace = true, features = ["uniffi", "experimental-search"] } mime = { version = "0.3.17", default-features = false } ruma = { workspace = true, features = [ "html", diff --git a/bindings/matrix-sdk-ffi/src/client_builder.rs b/bindings/matrix-sdk-ffi/src/client_builder.rs index 857683a69..f790bc5df 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -15,7 +15,7 @@ // Allow UniFFI to use methods marked as `#[deprecated]`. #![allow(deprecated)] -use std::{num::NonZeroUsize, sync::Arc, time::Duration}; +use std::{fs, num::NonZeroUsize, path::PathBuf, sync::Arc, time::Duration}; #[cfg(not(any(target_family = "wasm", target_os = "android")))] use matrix_sdk::reqwest::Certificate; @@ -26,6 +26,7 @@ use matrix_sdk::{ encryption::{BackupDownloadStrategy, EncryptionSettings}, event_cache::EventCacheError, ruma::{ServerName, UserId}, + search_index::SearchIndexStoreKind, sliding_sync::{ Error as MatrixSlidingSyncError, VersionBuilder as MatrixSlidingSyncVersionBuilder, VersionBuilderError, @@ -137,6 +138,7 @@ pub struct ClientBuilder { decryption_settings: DecryptionSettings, enable_share_history_on_invite: bool, request_config: Option, + search_index_store: Option, #[cfg(not(target_family = "wasm"))] user_agent: Option, @@ -193,6 +195,7 @@ impl ClientBuilder { enable_share_history_on_invite: false, request_config: Default::default(), threading_support: ThreadingSupport::Disabled, + search_index_store: None, }) } @@ -357,6 +360,26 @@ impl ClientBuilder { Arc::new(builder) } + pub fn with_search_index_store( + self: Arc, + path: String, + password: Option, + ) -> Arc { + let mut builder = unwrap_or_clone_arc(self); + + // Note: creation of the path is deferred to later. + let path = PathBuf::from(path); + + let kind = if let Some(password) = password { + SearchIndexStoreKind::EncryptedDirectory(path, password) + } else { + SearchIndexStoreKind::UnencryptedDirectory(path) + }; + + builder.search_index_store = Some(kind); + Arc::new(builder) + } + pub async fn build(self: Arc) -> Result, ClientBuildError> { let builder = unwrap_or_clone_arc(self); let mut inner_builder = MatrixClient::builder() @@ -385,6 +408,20 @@ impl ClientBuilder { None }; + if let Some(search_index_store) = builder.search_index_store { + // Create the search index directory. + match search_index_store { + SearchIndexStoreKind::UnencryptedDirectory(ref path) + | SearchIndexStoreKind::EncryptedDirectory(ref path, _) => { + fs::create_dir_all(path)?; + } + _ => {} + } + + // Configure the inner builder to use the search index store. + inner_builder = inner_builder.search_index_store(search_index_store); + } + // Determine server either from URL, server name or user ID. inner_builder = match builder.homeserver_cfg { Some(HomeserverConfig::Url(url)) => inner_builder.homeserver_url(url),