From 71b7f7fa4bc0ccecb3a5a3c9ac10e8f2096332c8 Mon Sep 17 00:00:00 2001 From: Ivan Enderlin Date: Mon, 11 Nov 2024 11:14:27 +0100 Subject: [PATCH] fix(ffi): Simplify `Client::new` constructor. This patch continues to simplification of the `matrix_sdk_ffi::Client`. The constructor can receive a `enable_oidc_refresh_crypto_lock: bool` instead of `cross_process_refresh_lock_id: Option`, which was a copy of `matrix_sdk::Client::cross_process_store_locks_holder_name`. Now there is a single boolean to indicate whether `Oidc::enable_cross_process_refresh_lock` should be called or not. If it has to be called, it is possible to re-use `matrix_sdk::Client::cross_process_store_locks_holder_name`. Once again, there is a single place to read this data, it's not copied over different semantics. --- bindings/matrix-sdk-ffi/src/client.rs | 12 +++++++----- bindings/matrix-sdk-ffi/src/client_builder.rs | 6 +----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/client.rs b/bindings/matrix-sdk-ffi/src/client.rs index c14533c842..46a67d5ed8 100644 --- a/bindings/matrix-sdk-ffi/src/client.rs +++ b/bindings/matrix-sdk-ffi/src/client.rs @@ -194,9 +194,7 @@ pub struct Client { impl Client { pub async fn new( sdk_client: MatrixClient, - // Copy of `MatrixClient::cross_process_store_locks_holder_name` if OIDC stuff has been - // enabled. - cross_process_refresh_lock_id: Option, + enable_oidc_refresh_crypto_lock: bool, session_delegate: Option>, ) -> Result { let session_verification_controller: Arc< @@ -212,22 +210,26 @@ impl Client { } }); + let cross_process_store_locks_holder_name = + sdk_client.cross_process_store_locks_holder_name().to_owned(); + let client = Client { inner: AsyncRuntimeDropped::new(sdk_client), delegate: RwLock::new(None), session_verification_controller, }; - if let Some(cross_process_store_locks_holder_name) = cross_process_refresh_lock_id { + if enable_oidc_refresh_crypto_lock { if session_delegate.is_none() { return Err(anyhow::anyhow!( "missing session delegates when enabling the cross-process lock" ))?; } + client .inner .oidc() - .enable_cross_process_refresh_lock(cross_process_store_locks_holder_name.clone()) + .enable_cross_process_refresh_lock(cross_process_store_locks_holder_name) .await?; } diff --git a/bindings/matrix-sdk-ffi/src/client_builder.rs b/bindings/matrix-sdk-ffi/src/client_builder.rs index f019aeb302..0208d391b7 100644 --- a/bindings/matrix-sdk-ffi/src/client_builder.rs +++ b/bindings/matrix-sdk-ffi/src/client_builder.rs @@ -627,11 +627,7 @@ impl ClientBuilder { Ok(Arc::new( Client::new( sdk_client, - if builder.enable_oidc_refresh_crypto_lock { - builder.cross_process_store_locks_holder_name - } else { - None - }, + builder.enable_oidc_refresh_crypto_lock, builder.session_delegate, ) .await?,