Add a store_path method on the FFI client.

This commit is contained in:
Doug
2022-07-20 10:32:37 +01:00
parent e37e62c92c
commit 05fab8c394
5 changed files with 23 additions and 0 deletions

View File

@@ -40,6 +40,8 @@ interface Client {
[Throws=ClientError]
void restore_login(string restore_token);
string? store_path();
string homeserver();
void start_sync();

View File

@@ -68,6 +68,10 @@ impl Client {
})
}
pub fn store_path(&self) -> Option<String> {
self.client.store().path().and_then(|path| path.into_os_string().into_string().ok())
}
pub fn set_delegate(&self, delegate: Option<Box<dyn ClientDelegate>>) {
*self.delegate.write() = delegate;
}

View File

@@ -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<PathBuf> {
None
}
async fn save_filter(&self, filter_name: &str, filter_id: &str) -> Result<()> {
self.save_filter(filter_name, filter_id).await
}

View File

@@ -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<T, E = StoreError> = std::result::Result<T, E>;
#[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<PathBuf>;
/// 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<PathBuf> {
self.inner.path()
}
/// Get all the rooms this store knows about.
pub fn get_rooms(&self) -> Vec<Room> {
self.rooms.iter().filter_map(|r| self.get_room(r.key())).collect()

View File

@@ -1381,6 +1381,9 @@ impl SledStore {
#[async_trait]
impl StateStore for SledStore {
fn path(&self) -> Option<PathBuf> {
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)
}