@@ -24,7 +24,7 @@ use std::{fmt, fs::File, path::Path};
24
24
use eyeball:: SharedObservable ;
25
25
use futures_util:: future:: try_join;
26
26
use matrix_sdk_base:: event_cache:: store:: media:: IgnoreMediaRetentionPolicy ;
27
- pub use matrix_sdk_base:: media:: * ;
27
+ pub use matrix_sdk_base:: { event_cache :: store :: media:: MediaRetentionPolicy , media :: * } ;
28
28
use mime:: Mime ;
29
29
use ruma:: {
30
30
api:: {
@@ -672,6 +672,44 @@ impl Media {
672
672
Ok ( ( ) )
673
673
}
674
674
675
+ /// Set the [`MediaRetentionPolicy`] to use for deciding whether to store or
676
+ /// keep media content.
677
+ ///
678
+ /// It is used:
679
+ ///
680
+ /// * When a media needs to be cached, to check that it does not exceed the
681
+ /// max file size.
682
+ ///
683
+ /// * When [`Media::clean_up_media_cache()`], to check that all media
684
+ /// content in the store fits those criteria.
685
+ ///
686
+ /// To apply the new policy to the media cache right away,
687
+ /// [`Media::clean_up_media_cache()`] should be called after this.
688
+ ///
689
+ /// By default, an empty `MediaRetentionPolicy` is used, which means that no
690
+ /// criteria are applied.
691
+ ///
692
+ /// # Arguments
693
+ ///
694
+ /// * `policy` - The `MediaRetentionPolicy` to use.
695
+ pub async fn set_media_retention_policy ( & self , policy : MediaRetentionPolicy ) -> Result < ( ) > {
696
+ self . client . event_cache_store ( ) . lock ( ) . await ?. set_media_retention_policy ( policy) . await ?;
697
+ Ok ( ( ) )
698
+ }
699
+
700
+ /// Get the current `MediaRetentionPolicy`.
701
+ pub async fn media_retention_policy ( & self ) -> Result < MediaRetentionPolicy > {
702
+ Ok ( self . client . event_cache_store ( ) . lock ( ) . await ?. media_retention_policy ( ) )
703
+ }
704
+
705
+ /// Clean up the media cache with the current [`MediaRetentionPolicy`].
706
+ ///
707
+ /// If there is already an ongoing cleanup, this is a noop.
708
+ pub async fn clean_up_media_cache ( & self ) -> Result < ( ) > {
709
+ self . client . event_cache_store ( ) . lock ( ) . await ?. clean_up_media_cache ( ) . await ?;
710
+ Ok ( ( ) )
711
+ }
712
+
675
713
/// Upload the file bytes in `data` and return the source information.
676
714
pub ( crate ) async fn upload_plain_media_and_thumbnail (
677
715
& self ,
0 commit comments