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_crypto_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 d608457 commit 71b7f7f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 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_crypto_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_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?;
}

Expand Down
6 changes: 1 addition & 5 deletions bindings/matrix-sdk-ffi/src/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand Down

0 comments on commit 71b7f7f

Please sign in to comment.