Skip to content

Commit b8fc5f4

Browse files
committed
ffi(client builder): inline build_inner into its one caller
No functional changes.
1 parent d531a7c commit b8fc5f4

File tree

1 file changed

+64
-64
lines changed

1 file changed

+64
-64
lines changed

bindings/matrix-sdk-ffi/src/client_builder.rs

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -435,68 +435,6 @@ impl ClientBuilder {
435435
}
436436

437437
pub async fn build(self: Arc<Self>) -> Result<Arc<Client>, ClientBuildError> {
438-
Ok(Arc::new(self.build_inner().await?))
439-
}
440-
441-
/// Finish the building of the client and attempt to log in using the
442-
/// provided [`QrCodeData`].
443-
///
444-
/// This method will build the client and immediately attempt to log the
445-
/// client in using the provided [`QrCodeData`] using the login
446-
/// mechanism described in [MSC4108]. As such this methods requires OIDC
447-
/// support as well as sliding sync support.
448-
///
449-
/// The usage of the progress_listener is required to transfer the
450-
/// [`CheckCode`] to the existing client.
451-
///
452-
/// [MSC4108]: https://github.com/matrix-org/matrix-spec-proposals/pull/4108
453-
pub async fn build_with_qr_code(
454-
self: Arc<Self>,
455-
qr_code_data: &QrCodeData,
456-
oidc_configuration: &OidcConfiguration,
457-
progress_listener: Box<dyn QrLoginProgressListener>,
458-
) -> Result<Arc<Client>, HumanQrLoginError> {
459-
if let QrCodeModeData::Reciprocate { server_name } = &qr_code_data.inner.mode_data {
460-
let builder = self.server_name_or_homeserver_url(server_name.to_owned());
461-
462-
let client = builder.build().await.map_err(|e| match e {
463-
ClientBuildError::SlidingSyncNotAvailable => {
464-
HumanQrLoginError::SlidingSyncNotAvailable
465-
}
466-
_ => {
467-
error!("Couldn't build the client {e:?}");
468-
HumanQrLoginError::Unknown
469-
}
470-
})?;
471-
472-
let client_metadata = oidc_configuration
473-
.try_into()
474-
.map_err(|_| HumanQrLoginError::OidcMetadataInvalid)?;
475-
476-
let oidc = client.inner.oidc();
477-
let login = oidc.login_with_qr_code(&qr_code_data.inner, client_metadata);
478-
479-
let mut progress = login.subscribe_to_progress();
480-
481-
// We create this task, which will get cancelled once it's dropped, just in case
482-
// the progress stream doesn't end.
483-
let _progress_task = TaskHandle::new(RUNTIME.spawn(async move {
484-
while let Some(state) = progress.next().await {
485-
progress_listener.on_update(state.into());
486-
}
487-
}));
488-
489-
login.await?;
490-
491-
Ok(client)
492-
} else {
493-
Err(HumanQrLoginError::OtherDeviceNotSignedIn)
494-
}
495-
}
496-
}
497-
498-
impl ClientBuilder {
499-
pub(crate) async fn build_inner(self: Arc<Self>) -> Result<Client, ClientBuildError> {
500438
let builder = unwrap_or_clone_arc(self);
501439
let mut inner_builder = MatrixClient::builder();
502440

@@ -605,7 +543,69 @@ impl ClientBuilder {
605543
sdk_client.set_sliding_sync_proxy(Some(Url::parse(&sliding_sync_proxy)?));
606544
}
607545

608-
Ok(Client::new(sdk_client, builder.cross_process_refresh_lock_id, builder.session_delegate)
609-
.await?)
546+
Ok(Arc::new(
547+
Client::new(
548+
sdk_client,
549+
builder.cross_process_refresh_lock_id,
550+
builder.session_delegate,
551+
)
552+
.await?,
553+
))
554+
}
555+
556+
/// Finish the building of the client and attempt to log in using the
557+
/// provided [`QrCodeData`].
558+
///
559+
/// This method will build the client and immediately attempt to log the
560+
/// client in using the provided [`QrCodeData`] using the login
561+
/// mechanism described in [MSC4108]. As such this methods requires OIDC
562+
/// support as well as sliding sync support.
563+
///
564+
/// The usage of the progress_listener is required to transfer the
565+
/// [`CheckCode`] to the existing client.
566+
///
567+
/// [MSC4108]: https://github.com/matrix-org/matrix-spec-proposals/pull/4108
568+
pub async fn build_with_qr_code(
569+
self: Arc<Self>,
570+
qr_code_data: &QrCodeData,
571+
oidc_configuration: &OidcConfiguration,
572+
progress_listener: Box<dyn QrLoginProgressListener>,
573+
) -> Result<Arc<Client>, HumanQrLoginError> {
574+
if let QrCodeModeData::Reciprocate { server_name } = &qr_code_data.inner.mode_data {
575+
let builder = self.server_name_or_homeserver_url(server_name.to_owned());
576+
577+
let client = builder.build().await.map_err(|e| match e {
578+
ClientBuildError::SlidingSyncNotAvailable => {
579+
HumanQrLoginError::SlidingSyncNotAvailable
580+
}
581+
_ => {
582+
error!("Couldn't build the client {e:?}");
583+
HumanQrLoginError::Unknown
584+
}
585+
})?;
586+
587+
let client_metadata = oidc_configuration
588+
.try_into()
589+
.map_err(|_| HumanQrLoginError::OidcMetadataInvalid)?;
590+
591+
let oidc = client.inner.oidc();
592+
let login = oidc.login_with_qr_code(&qr_code_data.inner, client_metadata);
593+
594+
let mut progress = login.subscribe_to_progress();
595+
596+
// We create this task, which will get cancelled once it's dropped, just in case
597+
// the progress stream doesn't end.
598+
let _progress_task = TaskHandle::new(RUNTIME.spawn(async move {
599+
while let Some(state) = progress.next().await {
600+
progress_listener.on_update(state.into());
601+
}
602+
}));
603+
604+
login.await?;
605+
606+
Ok(client)
607+
} else {
608+
Err(HumanQrLoginError::OtherDeviceNotSignedIn)
609+
}
610610
}
611611
}

0 commit comments

Comments
 (0)