From abffdf1877a31d4b97bd769782bfe719e4712cdd Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 7 Feb 2019 00:51:48 +0000 Subject: [PATCH] wip on loading rooms in session --- src/session.js | 11 ++++++++++- src/storage/idb/query-target.js | 2 +- src/storage/idb/stores/summary.js | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/storage/idb/stores/summary.js 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(); + } +}