@@ -76,6 +76,7 @@ pub struct ClientBuilder {
76
76
cross_process_refresh_lock_id : Option < String > ,
77
77
session_delegate : Option < Arc < dyn ClientSessionDelegate > > ,
78
78
additional_root_certificates : Vec < Vec < u8 > > ,
79
+ encryption_settings : EncryptionSettings ,
79
80
}
80
81
81
82
#[ uniffi:: export( async_runtime = "tokio" ) ]
@@ -93,14 +94,16 @@ impl ClientBuilder {
93
94
proxy : None ,
94
95
disable_ssl_verification : false ,
95
96
disable_automatic_token_refresh : false ,
96
- inner : MatrixClient :: builder ( ) . with_encryption_settings ( EncryptionSettings {
97
- auto_enable_cross_signing : false ,
98
- backup_download_strategy : BackupDownloadStrategy :: AfterDecryptionFailure ,
99
- auto_enable_backups : false ,
100
- } ) ,
97
+ inner : MatrixClient :: builder ( ) ,
101
98
cross_process_refresh_lock_id : None ,
102
99
session_delegate : None ,
103
100
additional_root_certificates : Default :: default ( ) ,
101
+ encryption_settings : EncryptionSettings {
102
+ auto_enable_cross_signing : false ,
103
+ backup_download_strategy :
104
+ matrix_sdk:: encryption:: BackupDownloadStrategy :: AfterDecryptionFailure ,
105
+ auto_enable_backups : false ,
106
+ } ,
104
107
} )
105
108
}
106
109
@@ -203,21 +206,41 @@ impl ClientBuilder {
203
206
Arc :: new ( builder)
204
207
}
205
208
206
- pub async fn build ( self : Arc < Self > ) -> Result < Arc < Client > , ClientBuildError > {
207
- Ok ( Arc :: new ( self . build_inner ( ) . await ?) )
209
+ pub fn auto_enable_cross_signing (
210
+ self : Arc < Self > ,
211
+ auto_enable_cross_signing : bool ,
212
+ ) -> Arc < Self > {
213
+ let mut builder = unwrap_or_clone_arc ( self ) ;
214
+ builder. encryption_settings . auto_enable_cross_signing = auto_enable_cross_signing;
215
+ Arc :: new ( builder)
208
216
}
209
- }
210
217
211
- impl ClientBuilder {
212
- pub ( crate ) fn with_encryption_settings (
218
+ /// Select a strategy to download room keys from the backup. By default
219
+ /// we download after a decryption failure.
220
+ ///
221
+ /// Take a look at the [`BackupDownloadStrategy`] enum for more options.
222
+ pub fn backup_download_strategy (
213
223
self : Arc < Self > ,
214
- settings : EncryptionSettings ,
224
+ backup_download_strategy : BackupDownloadStrategy ,
215
225
) -> Arc < Self > {
216
226
let mut builder = unwrap_or_clone_arc ( self ) ;
217
- builder. inner = builder . inner . with_encryption_settings ( settings ) ;
227
+ builder. encryption_settings . backup_download_strategy = backup_download_strategy ;
218
228
Arc :: new ( builder)
219
229
}
220
230
231
+ /// Automatically create a backup version if no backup exists.
232
+ pub fn auto_enable_backups ( self : Arc < Self > , auto_enable_backups : bool ) -> Arc < Self > {
233
+ let mut builder = unwrap_or_clone_arc ( self ) ;
234
+ builder. encryption_settings . auto_enable_backups = auto_enable_backups;
235
+ Arc :: new ( builder)
236
+ }
237
+
238
+ pub async fn build ( self : Arc < Self > ) -> Result < Arc < Client > , ClientBuildError > {
239
+ Ok ( Arc :: new ( self . build_inner ( ) . await ?) )
240
+ }
241
+ }
242
+
243
+ impl ClientBuilder {
221
244
pub ( crate ) fn enable_cross_process_refresh_lock_inner (
222
245
self : Arc < Self > ,
223
246
process_id : String ,
@@ -316,6 +339,8 @@ impl ClientBuilder {
316
339
) ;
317
340
}
318
341
342
+ inner_builder = inner_builder. with_encryption_settings ( builder. encryption_settings ) ;
343
+
319
344
let sdk_client = inner_builder. build ( ) . await ?;
320
345
321
346
// At this point, `sdk_client` might contain a `sliding_sync_proxy` that has
0 commit comments