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; } /**