From 747c00c265df5e5a6d1ef75affabb093a973fabb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Sun, 22 Oct 2023 15:10:40 +0200 Subject: [PATCH] Try to resume backups if we restore the client --- crates/matrix-sdk/src/client/mod.rs | 15 ++++++++++++++- crates/matrix-sdk/src/matrix_auth/mod.rs | 2 +- crates/matrix-sdk/src/oidc/mod.rs | 4 ++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/matrix-sdk/src/client/mod.rs b/crates/matrix-sdk/src/client/mod.rs index 4be9ddd71..6c36929c8 100644 --- a/crates/matrix-sdk/src/client/mod.rs +++ b/crates/matrix-sdk/src/client/mod.rs @@ -915,6 +915,19 @@ impl Client { } } + pub(crate) async fn set_session_meta(&self, session_meta: SessionMeta) -> Result<()> { + self.base_client().set_session_meta(session_meta).await?; + + #[cfg(feature = "e2e-encryption")] + { + if let Err(e) = self.encryption().backups().setup_and_resume().await { + error!("Couldn't setup and resume backups {e:?}"); + } + } + + Ok(()) + } + /// Refresh the access token using the authentication API used to log into /// this session. /// @@ -1955,7 +1968,7 @@ impl Client { // overwrite the session information shared with the parent too, and it // must be initialized at most once. if let Some(session) = self.session() { - client.base_client().set_session_meta(session.into_meta()).await?; + client.set_session_meta(session.into_meta()).await?; } Ok(client) diff --git a/crates/matrix-sdk/src/matrix_auth/mod.rs b/crates/matrix-sdk/src/matrix_auth/mod.rs index 61301bea9..40f6bebad 100644 --- a/crates/matrix-sdk/src/matrix_auth/mod.rs +++ b/crates/matrix-sdk/src/matrix_auth/mod.rs @@ -825,7 +825,7 @@ impl MatrixAuth { async fn set_session(&self, session: MatrixSession) -> Result<()> { self.set_session_tokens(session.tokens); - self.client.base_client().set_session_meta(session.meta).await?; + self.client.set_session_meta(session.meta).await?; Ok(()) } diff --git a/crates/matrix-sdk/src/oidc/mod.rs b/crates/matrix-sdk/src/oidc/mod.rs index 6e3dad276..2eb13d321 100644 --- a/crates/matrix-sdk/src/oidc/mod.rs +++ b/crates/matrix-sdk/src/oidc/mod.rs @@ -712,7 +712,7 @@ impl Oidc { authorization_data: Default::default(), }; - self.client.base_client().set_session_meta(meta).await?; + self.client.set_session_meta(meta).await?; self.deferred_enable_cross_process_refresh_lock().await?; self.client @@ -911,7 +911,7 @@ impl Oidc { device_id: whoami_res.device_id.ok_or(OidcError::MissingDeviceId)?, }; - self.client.base_client().set_session_meta(session).await.map_err(crate::Error::from)?; + self.client.set_session_meta(session).await.map_err(crate::Error::from)?; // At this point the Olm machine has been set up. // Enable the cross-process lock for refreshes, if needs be.