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();