forked from mystiq/hydrogen-web
wip on loading rooms in session
This commit is contained in:
parent
ec6bd2ca1f
commit
abffdf1877
3 changed files with 31 additions and 2 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) => {
|
||||
|
|
20
src/storage/idb/stores/summary.js
Normal file
20
src/storage/idb/stores/summary.js
Normal 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();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue