From 96119b4e583da025a780e78984798429c793e0f6 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 11 Sep 2020 14:41:40 +0200 Subject: [PATCH] load all pending operations when starting the session, pass to room --- src/matrix/Session.js | 14 +++++++++++++- src/matrix/room/Room.js | 11 +++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/matrix/Session.js b/src/matrix/Session.js index 7d821b14..f8ac2f40 100644 --- a/src/matrix/Session.js +++ b/src/matrix/Session.js @@ -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); } } diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index dea9545d..f4b69229 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -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();