Skip to content

Commit

Permalink
fix(ffi): Simplify Client::new constructor.
Browse files Browse the repository at this point in the history
This patch continues to simplification of the `matrix_sdk_ffi::Client`.
The constructor can receive a `enable_oidc_refresh_lock: bool` instead
of `cross_process_refresh_lock_id: Option<String>`, 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.
  • Loading branch information
Hywan committed Nov 11, 2024
1 parent d3a2326 commit 4d39d17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
12 changes: 7 additions & 5 deletions bindings/matrix-sdk-ffi/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
enable_oidc_refresh_lock: bool,
session_delegate: Option<Arc<dyn ClientSessionDelegate>>,
) -> Result<Self, ClientError> {
let session_verification_controller: Arc<
Expand All @@ -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_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?;
}

Expand Down
20 changes: 6 additions & 14 deletions bindings/matrix-sdk-ffi/src/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub struct ClientBuilder {
disable_ssl_verification: bool,
disable_automatic_token_refresh: bool,
cross_process_store_locks_holder_name: Option<String>,
enable_oidc_refresh_crypto_lock: bool,
enable_oidc_refresh_lock: bool,
session_delegate: Option<Arc<dyn ClientSessionDelegate>>,
additional_root_certificates: Vec<Vec<u8>>,
disable_built_in_root_certificates: bool,
Expand All @@ -286,7 +286,7 @@ impl ClientBuilder {
disable_ssl_verification: false,
disable_automatic_token_refresh: false,
cross_process_store_locks_holder_name: None,
enable_oidc_refresh_crypto_lock: false,
enable_oidc_refresh_lock: false,
session_delegate: None,
additional_root_certificates: Default::default(),
disable_built_in_root_certificates: false,
Expand All @@ -311,9 +311,9 @@ impl ClientBuilder {
Arc::new(builder)
}

pub fn enable_oidc_refresh_crypto_lock(self: Arc<Self>) -> Arc<Self> {
pub fn enable_oidc_refresh_lock(self: Arc<Self>) -> Arc<Self> {
let mut builder = unwrap_or_clone_arc(self);
builder.enable_oidc_refresh_crypto_lock = true;
builder.enable_oidc_refresh_lock = true;
Arc::new(builder)
}

Expand Down Expand Up @@ -625,16 +625,8 @@ impl ClientBuilder {
let sdk_client = inner_builder.build().await?;

Ok(Arc::new(
Client::new(
sdk_client,
if builder.enable_oidc_refresh_crypto_lock {
builder.cross_process_store_locks_holder_name
} else {
None
},
builder.session_delegate,
)
.await?,
Client::new(sdk_client, builder.enable_oidc_refresh_lock, builder.session_delegate)
.await?,
))
}

Expand Down

0 comments on commit 4d39d17

Please sign in to comment.