From 05fab8c394c44d05328e5375b1cf50859e1237a5 Mon Sep 17 00:00:00 2001 From: Doug Date: Wed, 20 Jul 2022 10:32:37 +0100 Subject: [PATCH] Add a store_path method on the FFI client. --- bindings/matrix-sdk-ffi/src/api.udl | 2 ++ bindings/matrix-sdk-ffi/src/client.rs | 4 ++++ crates/matrix-sdk-base/src/store/memory_store.rs | 5 +++++ crates/matrix-sdk-base/src/store/mod.rs | 9 +++++++++ crates/matrix-sdk-sled/src/state_store.rs | 3 +++ 5 files changed, 23 insertions(+) diff --git a/bindings/matrix-sdk-ffi/src/api.udl b/bindings/matrix-sdk-ffi/src/api.udl index 76d2ada9f..26af46e68 100644 --- a/bindings/matrix-sdk-ffi/src/api.udl +++ b/bindings/matrix-sdk-ffi/src/api.udl @@ -40,6 +40,8 @@ interface Client { [Throws=ClientError] void restore_login(string restore_token); + string? store_path(); + string homeserver(); void start_sync(); diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 35538cb84..e8d9f4304 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -68,6 +68,10 @@ impl Client { }) } + pub fn store_path(&self) -> Option { + self.client.store().path().and_then(|path| path.into_os_string().into_string().ok()) + } + pub fn set_delegate(&self, delegate: Option>) { *self.delegate.write() = delegate; } diff --git a/crates/matrix-sdk-base/src/store/memory_store.rs b/crates/matrix-sdk-base/src/store/memory_store.rs index 03187a5c1..de7ac141e 100644 --- a/crates/matrix-sdk-base/src/store/memory_store.rs +++ b/crates/matrix-sdk-base/src/store/memory_store.rs @@ -16,6 +16,7 @@ use std::collections::{BTreeMap, HashMap}; use std::{ collections::BTreeSet, + path::PathBuf, sync::{Arc, RwLock}, }; @@ -692,6 +693,10 @@ impl MemoryStore { #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] impl StateStore for MemoryStore { + fn path(&self) -> Option { + None + } + async fn save_filter(&self, filter_name: &str, filter_id: &str) -> Result<()> { self.save_filter(filter_name, filter_id).await } diff --git a/crates/matrix-sdk-base/src/store/mod.rs b/crates/matrix-sdk-base/src/store/mod.rs index a135d782c..df6e32435 100644 --- a/crates/matrix-sdk-base/src/store/mod.rs +++ b/crates/matrix-sdk-base/src/store/mod.rs @@ -23,6 +23,7 @@ use std::{ collections::{BTreeMap, BTreeSet}, ops::Deref, + path::PathBuf, pin::Pin, result::Result as StdResult, sync::Arc, @@ -130,6 +131,9 @@ pub type Result = std::result::Result; #[cfg_attr(target_arch = "wasm32", async_trait(?Send))] #[cfg_attr(not(target_arch = "wasm32"), async_trait)] pub trait StateStore: AsyncTraitDeps { + /// The path used by the store, or `None` if the store is in memory. + fn path(&self) -> Option; + /// Save the given filter id under the given name. /// /// # Arguments @@ -464,6 +468,11 @@ impl Store { self.session.get() } + /// The path used by the store, or `None` if the store is in memory. + pub fn path(&self) -> Option { + self.inner.path() + } + /// Get all the rooms this store knows about. pub fn get_rooms(&self) -> Vec { self.rooms.iter().filter_map(|r| self.get_room(r.key())).collect() diff --git a/crates/matrix-sdk-sled/src/state_store.rs b/crates/matrix-sdk-sled/src/state_store.rs index 745270ef2..ab491c533 100644 --- a/crates/matrix-sdk-sled/src/state_store.rs +++ b/crates/matrix-sdk-sled/src/state_store.rs @@ -1381,6 +1381,9 @@ impl SledStore { #[async_trait] impl StateStore for SledStore { + fn path(&self) -> Option { + self.path.clone() + } async fn save_filter(&self, filter_name: &str, filter_id: &str) -> StoreResult<()> { self.save_filter(filter_name, filter_id).await.map_err(Into::into) }