add logging to key sharing and discarding in reaction to member changes
This commit is contained in:
parent
f3c49e51f2
commit
30481a5a9e
2 changed files with 13 additions and 4 deletions
|
@ -79,14 +79,18 @@ export class RoomEncryption {
|
|||
this._senderDeviceCache = new Map(); // purge the sender device cache
|
||||
}
|
||||
|
||||
async writeMemberChanges(memberChanges, txn) {
|
||||
async writeMemberChanges(memberChanges, txn, log) {
|
||||
let shouldFlush;
|
||||
const memberChangesArray = Array.from(memberChanges.values());
|
||||
if (memberChangesArray.some(m => m.hasLeft)) {
|
||||
log.log({
|
||||
l: "discardOutboundSession",
|
||||
leftUsers: memberChangesArray.filter(m => m.hasLeft).map(m => m.userId),
|
||||
});
|
||||
this._megolmEncryption.discardOutboundSession(this._room.id, txn);
|
||||
}
|
||||
if (memberChangesArray.some(m => m.hasJoined)) {
|
||||
shouldFlush = await this._addShareRoomKeyOperationForNewMembers(memberChangesArray, txn);
|
||||
shouldFlush = await this._addShareRoomKeyOperationForNewMembers(memberChangesArray, txn, log);
|
||||
}
|
||||
await this._deviceTracker.writeMemberChanges(this._room, memberChanges, txn);
|
||||
return shouldFlush;
|
||||
|
@ -310,11 +314,16 @@ export class RoomEncryption {
|
|||
await removeOpTxn.complete();
|
||||
}
|
||||
|
||||
async _addShareRoomKeyOperationForNewMembers(memberChangesArray, txn) {
|
||||
async _addShareRoomKeyOperationForNewMembers(memberChangesArray, txn, log) {
|
||||
const userIds = memberChangesArray.filter(m => m.hasJoined).map(m => m.userId);
|
||||
const roomKeyMessage = await this._megolmEncryption.createRoomKeyMessage(
|
||||
this._room.id, txn);
|
||||
if (roomKeyMessage) {
|
||||
log.log({
|
||||
l: "share key for new members", userIds,
|
||||
id: roomKeyMessage.session_id,
|
||||
chain_index: roomKeyMessage.chain_index
|
||||
});
|
||||
this._writeRoomKeyShareOperation(roomKeyMessage, userIds, txn);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -256,7 +256,7 @@ export class Room extends EventEmitter {
|
|||
let shouldFlushKeyShares = false;
|
||||
// pass member changes to device tracker
|
||||
if (roomEncryption && this.isTrackingMembers && memberChanges?.size) {
|
||||
shouldFlushKeyShares = await roomEncryption.writeMemberChanges(memberChanges, txn);
|
||||
shouldFlushKeyShares = await roomEncryption.writeMemberChanges(memberChanges, txn, log);
|
||||
log.set("shouldFlushKeyShares", shouldFlushKeyShares);
|
||||
}
|
||||
// also apply (decrypted) timeline entries to the summary changes
|
||||
|
|
Reference in a new issue