@@ -2,21 +2,20 @@ use std::{
2
2
collections:: HashMap ,
3
3
fmt:: Debug ,
4
4
path:: PathBuf ,
5
- sync:: { Arc , OnceLock , RwLock } ,
5
+ sync:: { Arc , OnceLock } ,
6
6
time:: Duration ,
7
7
} ;
8
8
9
9
use anyhow:: { anyhow, Context as _} ;
10
10
use futures_util:: pin_mut;
11
+ #[ cfg( not( target_family = "wasm" ) ) ]
12
+ use matrix_sdk:: media:: MediaFileHandle as SdkMediaFileHandle ;
11
13
use matrix_sdk:: {
12
14
authentication:: oauth:: {
13
15
AccountManagementActionFull , ClientId , OAuthAuthorizationData , OAuthSession ,
14
16
} ,
15
17
event_cache:: EventCacheError ,
16
- media:: {
17
- MediaFileHandle as SdkMediaFileHandle , MediaFormat , MediaRequestParameters ,
18
- MediaRetentionPolicy , MediaThumbnailSettings ,
19
- } ,
18
+ media:: { MediaFormat , MediaRequestParameters , MediaRetentionPolicy , MediaThumbnailSettings } ,
20
19
ruma:: {
21
20
api:: client:: {
22
21
discovery:: {
@@ -493,32 +492,6 @@ impl Client {
493
492
Ok ( ( ) )
494
493
}
495
494
496
- pub async fn get_media_file (
497
- & self ,
498
- media_source : Arc < MediaSource > ,
499
- filename : Option < String > ,
500
- mime_type : String ,
501
- use_cache : bool ,
502
- temp_dir : Option < String > ,
503
- ) -> Result < Arc < MediaFileHandle > , ClientError > {
504
- let source = ( * media_source) . clone ( ) ;
505
- let mime_type: mime:: Mime = mime_type. parse ( ) ?;
506
-
507
- let handle = self
508
- . inner
509
- . media ( )
510
- . get_media_file (
511
- & MediaRequestParameters { source : source. media_source , format : MediaFormat :: File } ,
512
- filename,
513
- & mime_type,
514
- use_cache,
515
- temp_dir,
516
- )
517
- . await ?;
518
-
519
- Ok ( Arc :: new ( MediaFileHandle :: new ( handle) ) )
520
- }
521
-
522
495
/// Restores the client from a `Session`.
523
496
///
524
497
/// It reloads the entire set of rooms from the previous session.
@@ -736,6 +709,39 @@ impl Client {
736
709
}
737
710
}
738
711
712
+ #[ cfg( not( target_family = "wasm" ) ) ]
713
+ #[ matrix_sdk_ffi_macros:: export]
714
+ impl Client {
715
+ /// Retrieves a media file from the media source
716
+ ///
717
+ /// Not available on Wasm platforms, due to lack of accessible file system.
718
+ pub async fn get_media_file (
719
+ & self ,
720
+ media_source : Arc < MediaSource > ,
721
+ filename : Option < String > ,
722
+ mime_type : String ,
723
+ use_cache : bool ,
724
+ temp_dir : Option < String > ,
725
+ ) -> Result < Arc < MediaFileHandle > , ClientError > {
726
+ let source = ( * media_source) . clone ( ) ;
727
+ let mime_type: mime:: Mime = mime_type. parse ( ) ?;
728
+
729
+ let handle = self
730
+ . inner
731
+ . media ( )
732
+ . get_media_file (
733
+ & MediaRequestParameters { source : source. media_source , format : MediaFormat :: File } ,
734
+ filename,
735
+ & mime_type,
736
+ use_cache,
737
+ temp_dir,
738
+ )
739
+ . await ?;
740
+
741
+ Ok ( Arc :: new ( MediaFileHandle :: new ( handle) ) )
742
+ }
743
+ }
744
+
739
745
impl Client {
740
746
/// Whether or not the client's homeserver supports the password login flow.
741
747
pub ( crate ) async fn supports_password_login ( & self ) -> anyhow:: Result < bool > {
@@ -2166,17 +2172,20 @@ fn gen_transaction_id() -> String {
2166
2172
2167
2173
/// A file handle that takes ownership of a media file on disk. When the handle
2168
2174
/// is dropped, the file will be removed from the disk.
2175
+ #[ cfg( not( target_family = "wasm" ) ) ]
2169
2176
#[ derive( uniffi:: Object ) ]
2170
2177
pub struct MediaFileHandle {
2171
- inner : RwLock < Option < SdkMediaFileHandle > > ,
2178
+ inner : std :: sync :: RwLock < Option < SdkMediaFileHandle > > ,
2172
2179
}
2173
2180
2181
+ #[ cfg( not( target_family = "wasm" ) ) ]
2174
2182
impl MediaFileHandle {
2175
2183
fn new ( handle : SdkMediaFileHandle ) -> Self {
2176
- Self { inner : RwLock :: new ( Some ( handle) ) }
2184
+ Self { inner : std :: sync :: RwLock :: new ( Some ( handle) ) }
2177
2185
}
2178
2186
}
2179
2187
2188
+ #[ cfg( not( target_family = "wasm" ) ) ]
2180
2189
#[ matrix_sdk_ffi_macros:: export]
2181
2190
impl MediaFileHandle {
2182
2191
/// Get the media file's path.
0 commit comments