feat(ffi): allow enabling search with a search index store

This commit is contained in:
Benjamin Bouvier
2026-03-26 17:27:18 +01:00
parent 717b6371f8
commit 83989c030a
2 changed files with 39 additions and 2 deletions
+1 -1
View File
@@ -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",
+38 -1
View File
@@ -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<RequestConfig>,
search_index_store: Option<SearchIndexStoreKind>,
#[cfg(not(target_family = "wasm"))]
user_agent: Option<String>,
@@ -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<Self>,
path: String,
password: Option<String>,
) -> Arc<Self> {
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<Self>) -> Result<Arc<Client>, 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),