wip on loading rooms in session

This commit is contained in:
Bruno Windels 2019-02-07 00:51:48 +00:00
parent ec6bd2ca1f
commit abffdf1877
3 changed files with 31 additions and 2 deletions

View file

@ -14,12 +14,21 @@ export default class Session {
}
async load() {
const txn = this._storage.readTxn([this._storage.storeNames.session]);
const txn = this._storage.readTxn([
this._storage.storeNames.session,
this._storage.storeNames.roomSummary,
]);
// restore session object
this._session = await txn.session.get();
if (!this._session) {
throw new Error("session store is empty");
}
// load rooms
const rooms = await txn.roomSummary.getAll();
await Promise.all(rooms.map(roomSummary => {
const room = this.createRoom(room.roomId);
return room.load(roomSummary);
}));
}
getRoom(roomId) {

View file

@ -29,7 +29,7 @@ export default class QueryTarget {
return this._selectWhile(range, predicate, "prev");
}
selectAll(range) {
selectAll(range, direction) {
const cursor = this._target.openCursor(range, direction);
const results = [];
return iterateCursor(cursor, (value) => {

View file

@ -0,0 +1,20 @@
/**
store contains:
roomId
name
lastMessage
unreadCount
mentionCount
isEncrypted
isDirectMessage
membership
*/
export default class RoomSummaryStore {
constructor(summaryStore) {
this._summaryStore = summaryStore;
}
getAll() {
return this._summaryStore.selectAll();
}
}