base: Restore stripped room infos as well

master
Damir Jelić 2021-01-23 17:29:43 +01:00
parent 44974982e1
commit eb8138ca6a
4 changed files with 46 additions and 7 deletions

View File

@ -36,14 +36,24 @@ impl StrippedRoom {
pub fn new(own_user_id: &UserId, store: Arc<Box<dyn StateStore>>, room_id: &RoomId) -> Self {
let room_id = Arc::new(room_id.clone());
let info = StrippedRoomInfo {
room_id,
base_info: BaseRoomInfo::new(),
};
Self::restore(own_user_id, store, info)
}
pub fn restore(
own_user_id: &UserId,
store: Arc<Box<dyn StateStore>>,
room_info: StrippedRoomInfo,
) -> Self {
Self {
own_user_id: Arc::new(own_user_id.clone()),
room_id: room_id.clone(),
room_id: room_info.room_id.clone(),
store,
inner: Arc::new(SyncMutex::new(StrippedRoomInfo {
room_id,
base_info: BaseRoomInfo::new(),
})),
inner: Arc::new(SyncMutex::new(room_info)),
}
}

View File

@ -275,6 +275,11 @@ impl MemoryStore {
#[allow(clippy::map_clone)]
self.room_info.iter().map(|r| r.clone()).collect()
}
fn get_stripped_room_infos(&self) -> Vec<StrippedRoomInfo> {
#[allow(clippy::map_clone)]
self.stripped_room_info.iter().map(|r| r.clone()).collect()
}
}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
@ -336,4 +341,8 @@ impl StateStore for MemoryStore {
async fn get_room_infos(&self) -> Result<Vec<RoomInfo>> {
Ok(self.get_room_infos())
}
async fn get_stripped_room_infos(&self) -> Result<Vec<StrippedRoomInfo>> {
Ok(self.get_stripped_room_infos())
}
}

View File

@ -99,6 +99,8 @@ pub trait StateStore: AsyncTraitDeps {
async fn get_joined_user_ids(&self, room_id: &RoomId) -> Result<Vec<UserId>>;
async fn get_room_infos(&self) -> Result<Vec<RoomInfo>>;
async fn get_stripped_room_infos(&self) -> Result<Vec<StrippedRoomInfo>>;
}
#[derive(Debug, Clone)]
@ -125,11 +127,16 @@ impl Store {
}
pub(crate) async fn restore_session(&self, session: Session) -> Result<()> {
for info in self.inner.get_room_infos().await?.into_iter() {
for info in self.inner.get_room_infos().await? {
let room = Room::restore(&session.user_id, self.inner.clone(), info);
self.rooms.insert(room.room_id().to_owned(), room);
}
for info in self.inner.get_stripped_room_infos().await? {
let room = StrippedRoom::restore(&session.user_id, self.inner.clone(), info);
self.stripped_rooms.insert(room.room_id().to_owned(), room);
}
let token = self.get_sync_token().await?;
*self.sync_token.write().await = token;

View File

@ -37,7 +37,7 @@ use sled::{
};
use tracing::info;
use crate::deserialized_responses::MemberEvent;
use crate::{deserialized_responses::MemberEvent, rooms::StrippedRoomInfo};
use self::store_key::{EncryptedEvent, StoreKey};
@ -479,6 +479,15 @@ impl SledStore {
.map(move |r| db.deserialize_event(&r?.1).map_err(|e| e.into())),
)
}
pub async fn get_stripped_room_infos(&self) -> impl Stream<Item = Result<StrippedRoomInfo>> {
let db = self.clone();
stream::iter(
self.stripped_room_info
.iter()
.map(move |r| db.deserialize_event(&r?.1).map_err(|e| e.into())),
)
}
}
#[async_trait]
@ -539,6 +548,10 @@ impl StateStore for SledStore {
async fn get_room_infos(&self) -> Result<Vec<RoomInfo>> {
self.get_room_infos().await.try_collect().await
}
async fn get_stripped_room_infos(&self) -> Result<Vec<StrippedRoomInfo>> {
self.get_stripped_room_infos().await.try_collect().await
}
}
#[cfg(test)]