load all pending operations when starting the session, pass to room

This commit is contained in:
Bruno Windels 2020-09-11 14:41:40 +02:00
parent ab1fe711ad
commit 96119b4e58
2 changed files with 20 additions and 5 deletions

View file

@ -28,6 +28,7 @@ import {MEGOLM_ALGORITHM} from "./e2ee/common.js";
import {RoomEncryption} from "./e2ee/RoomEncryption.js";
import {DeviceTracker} from "./e2ee/DeviceTracker.js";
import {LockMap} from "../utils/LockMap.js";
import {groupBy} from "../utils/groupBy.js";
const PICKLE_KEY = "DEFAULT_KEY";
@ -212,9 +213,20 @@ export class Session {
await txn.complete();
}
const opsTxn = await this._storage.readWriteTxn([
this._storage.storeNames.operations
]);
const operations = await opsTxn.operations.getAll();
const operationsByScope = groupBy(operations, o => o.scope);
this._sendScheduler.start();
for (const [, room] of this._rooms) {
room.start();
let roomOperationsByType;
const roomOperations = operationsByScope.get(room.id);
if (roomOperations) {
roomOperationsByType = groupBy(roomOperations, r => r.type);
}
room.start(roomOperationsByType);
}
}

View file

@ -259,14 +259,17 @@ export class Room extends EventEmitter {
}
/** @package */
async start() {
async start(pendingOperations) {
if (this._roomEncryption) {
try {
// if we got interrupted last time sending keys to newly joined members
await this._roomEncryption.shareRoomKeyToPendingMembers(this._hsApi);
const roomKeyShares = pendingOperations?.get("share_room_key");
if (roomKeyShares) {
// if we got interrupted last time sending keys to newly joined members
await this._roomEncryption.flushPendingRoomKeyShares(this._hsApi, roomKeyShares);
}
} catch (err) {
// we should not throw here
console.error(`could not send out pending room keys for room ${this.id}`, err.stack);
console.error(`could not send out (all) pending room keys for room ${this.id}`, err.stack);
}
}
this._sendQueue.resumeSending();