From 6aea4c827a8472abff782b08c2e4bfe2bfe96f8f Mon Sep 17 00:00:00 2001 From: Benjamin Bouvier Date: Mon, 3 Mar 2025 16:21:49 +0100 Subject: [PATCH] feat(ffi): allow setting the media retention policy from the FFI layer --- bindings/matrix-sdk-ffi/src/client.rs | 15 ++++++++++++++- .../store/media/media_retention_policy.rs | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index 2301b1595..e48517114 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -21,7 +21,7 @@ use matrix_sdk::{ event_cache::EventCacheError, media::{ MediaFileHandle as SdkMediaFileHandle, MediaFormat, MediaRequestParameters, - MediaThumbnailSettings, + MediaRetentionPolicy, MediaThumbnailSettings, }, ruma::{ api::client::{ @@ -1161,6 +1161,19 @@ impl Client { self.inner.is_room_alias_available(&alias).await.map_err(Into::into) } + /// Set the media retention policy. + pub async fn set_media_retention_policy( + &self, + policy: MediaRetentionPolicy, + ) -> Result<(), ClientError> { + let closure = async || -> Result<_, EventCacheError> { + let store = self.inner.event_cache_store().lock().await?; + Ok(store.set_media_retention_policy(policy).await?) + }; + + Ok(closure().await?) + } + /// Clear all the non-critical caches for this Client instance. /// /// - This will empty all the room's persisted event caches, so all rooms diff --git a/crates/matrix-sdk-base/src/event_cache/store/media/media_retention_policy.rs b/crates/matrix-sdk-base/src/event_cache/store/media/media_retention_policy.rs index 92757fd72..4128c8ec0 100644 --- a/crates/matrix-sdk-base/src/event_cache/store/media/media_retention_policy.rs +++ b/crates/matrix-sdk-base/src/event_cache/store/media/media_retention_policy.rs @@ -33,6 +33,7 @@ use serde::{Deserialize, Serialize}; /// /// [`EventCacheStore`]: crate::event_cache::store::EventCacheStore #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[cfg_attr(feature = "uniffi", derive(uniffi::Record))] #[non_exhaustive] pub struct MediaRetentionPolicy { /// The maximum authorized size of the overall media cache, in bytes.