diff --git a/src/session.js b/src/session.js index 9bae825b..515281d8 100644 --- a/src/session.js +++ b/src/session.js @@ -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) { diff --git a/src/storage/idb/query-target.js b/src/storage/idb/query-target.js index 0d792c61..c8052dfb 100644 --- a/src/storage/idb/query-target.js +++ b/src/storage/idb/query-target.js @@ -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) => { diff --git a/src/storage/idb/stores/summary.js b/src/storage/idb/stores/summary.js new file mode 100644 index 00000000..e0487522 --- /dev/null +++ b/src/storage/idb/stores/summary.js @@ -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(); + } +}