mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
wip on loading rooms in session
This commit is contained in:
parent
ec6bd2ca1f
commit
abffdf1877
@ -14,12 +14,21 @@ export default class Session {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async load() {
|
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();
|
this._session = await txn.session.get();
|
||||||
if (!this._session) {
|
if (!this._session) {
|
||||||
throw new Error("session store is empty");
|
throw new Error("session store is empty");
|
||||||
}
|
}
|
||||||
// load rooms
|
// 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) {
|
getRoom(roomId) {
|
||||||
|
@ -29,7 +29,7 @@ export default class QueryTarget {
|
|||||||
return this._selectWhile(range, predicate, "prev");
|
return this._selectWhile(range, predicate, "prev");
|
||||||
}
|
}
|
||||||
|
|
||||||
selectAll(range) {
|
selectAll(range, direction) {
|
||||||
const cursor = this._target.openCursor(range, direction);
|
const cursor = this._target.openCursor(range, direction);
|
||||||
const results = [];
|
const results = [];
|
||||||
return iterateCursor(cursor, (value) => {
|
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 New Issue
Block a user