This commit is contained in:
Bruno Windels 2021-03-02 19:14:29 +01:00
parent e29bc6710a
commit 56db210763
2 changed files with 11 additions and 4 deletions

View file

@ -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) {

View file

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