From 56db210763bfd5e6ce33d9b6bfa4a92fa0829b1e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 2 Mar 2021 19:14:29 +0100 Subject: [PATCH] attempt at fixing https://github.com/vector-im/hydrogen-web/issues/245 --- src/matrix/e2ee/RoomEncryption.js | 6 +++++- src/matrix/room/Room.js | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/matrix/e2ee/RoomEncryption.js b/src/matrix/e2ee/RoomEncryption.js index 07e62749..3cf1310d 100644 --- a/src/matrix/e2ee/RoomEncryption.js +++ b/src/matrix/e2ee/RoomEncryption.js @@ -80,14 +80,16 @@ export class RoomEncryption { } async writeMemberChanges(memberChanges, txn) { + let shouldFlush; const memberChangesArray = Array.from(memberChanges.values()); if (memberChangesArray.some(m => m.hasLeft)) { this._megolmEncryption.discardOutboundSession(this._room.id, txn); } if (memberChangesArray.some(m => m.hasJoined)) { - await this._addShareRoomKeyOperationForNewMembers(memberChangesArray, txn); + shouldFlush = await this._addShareRoomKeyOperationForNewMembers(memberChangesArray, txn); } await this._deviceTracker.writeMemberChanges(this._room, memberChanges, txn); + return shouldFlush; } // this happens before entries exists, as they are created by the syncwriter @@ -314,7 +316,9 @@ export class RoomEncryption { this._room.id, txn); if (roomKeyMessage) { this._writeRoomKeyShareOperation(roomKeyMessage, userIds, txn); + return true; } + return false; } _writeRoomKeyShareOperation(roomKeyMessage, userIds, txn) { diff --git a/src/matrix/room/Room.js b/src/matrix/room/Room.js index 27fd32f9..198652c7 100644 --- a/src/matrix/room/Room.js +++ b/src/matrix/room/Room.js @@ -232,9 +232,11 @@ export class Room extends EventEmitter { } decryption.applyToEntries(entries); } + let shouldFlushKeyShares = false; // pass member changes to device tracker if (roomEncryption && this.isTrackingMembers && memberChanges?.size) { - await roomEncryption.writeMemberChanges(memberChanges, txn); + shouldFlushKeyShares = await roomEncryption.writeMemberChanges(memberChanges, txn); + log.set("shouldFlushKeyShares", shouldFlushKeyShares); } // also apply (decrypted) timeline entries to the summary changes summaryChanges = summaryChanges.applyTimelineEntries( @@ -263,6 +265,7 @@ export class Room extends EventEmitter { removedPendingEvents, memberChanges, heroChanges, + shouldFlushKeyShares, }; } @@ -314,8 +317,8 @@ export class Room extends EventEmitter { } } - needsAfterSyncCompleted({memberChanges}) { - return this._roomEncryption?.needsToShareKeys(memberChanges); + needsAfterSyncCompleted({shouldFlushKeyShares}) { + return shouldFlushKeyShares; } /**