From 11aa306de2e9fb652f53c0f9f12b9705c52fb185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 6 Jul 2020 10:54:01 +0200 Subject: [PATCH] base: Swap around the store creation. The state store creates directory structure but the crypto store does not. This can lead to confusing errors where we require a directory to be created by the library user but it gets created by the library. --- matrix_sdk_base/src/client.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index 975c7c6d..89abdbb8 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -458,6 +458,20 @@ impl BaseClient { /// * `session` - An session that the user already has from a /// previous login call. pub async fn restore_login(&self, session: Session) -> Result<()> { + // If there wasn't a state store opened, try to open the default one if + // a store path was provided. + if self.state_store.read().await.is_none() { + #[cfg(not(target_arch = "wasm32"))] + { + if let Some(path) = &*self.store_path { + let store = JsonStore::open(path)?; + *self.state_store.write().await = Some(Box::new(store)); + } + } + } + + self.sync_with_state_store(&session).await?; + #[cfg(feature = "encryption")] { let mut olm = self.olm.lock().await; @@ -496,20 +510,6 @@ impl BaseClient { } } - // If there wasn't a state store opened, try to open the default one if - // a store path was provided. - if self.state_store.read().await.is_none() { - #[cfg(not(target_arch = "wasm32"))] - { - if let Some(path) = &*self.store_path { - let store = JsonStore::open(path)?; - *self.state_store.write().await = Some(Box::new(store)); - } - } - } - - self.sync_with_state_store(&session).await?; - *self.session.write().await = Some(session); Ok(())