base: Restore rooms and the sync token when we restore the login.
This commit is contained in:
parent
4d7da05b90
commit
0952205e1e
2 changed files with 17 additions and 12 deletions
|
@ -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")]
|
||||
{
|
||||
|
|
|
@ -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<Path>) -> Self {
|
||||
let inner = SledStore::open_with_path(path);
|
||||
Self::new(
|
||||
|
|
Loading…
Reference in a new issue