diff --git a/matrix_sdk_base/src/client.rs b/matrix_sdk_base/src/client.rs index bbd086ac..de3862cc 100644 --- a/matrix_sdk_base/src/client.rs +++ b/matrix_sdk_base/src/client.rs @@ -352,17 +352,7 @@ 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?; + self.store.restore_session(session.clone()).await; #[cfg(feature = "encryption")] { diff --git a/matrix_sdk_base/src/store.rs b/matrix_sdk_base/src/store.rs index 85c4b386..25b6f160 100644 --- a/matrix_sdk_base/src/store.rs +++ b/matrix_sdk_base/src/store.rs @@ -3,7 +3,7 @@ use std::{ }; use dashmap::DashMap; -use futures::stream::{self, Stream}; +use futures::stream::{self, Stream, StreamExt}; use matrix_sdk_common::{ events::{ presence::PresenceEvent, @@ -47,6 +47,21 @@ impl Store { } } + pub(crate) async fn restore_session(&self, session: Session) { + let mut infos = self.inner.get_room_infos().await; + + // TODO restore stripped rooms. + while let Some(info) = infos.next().await { + let room = Room::restore(&session.user_id, self.inner.clone(), info); + self.rooms.insert(room.room_id().to_owned(), room); + } + + let token = self.get_sync_token().await; + + *self.sync_token.write().await = token; + *self.session.write().await = Some(session); + } + pub fn open_default(path: impl AsRef) -> Self { let inner = SledStore::open_with_path(path); Self::new(