From f271517446e9e4a4c19ddb4054b1885a622545ad Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 20 May 2021 15:02:14 +0200 Subject: [PATCH] log redaction during sync --- src/matrix/room/timeline/persistence/GapWriter.js | 8 ++++---- .../room/timeline/persistence/RelationWriter.js | 12 +++++++----- src/matrix/room/timeline/persistence/SyncWriter.js | 4 ++-- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/matrix/room/timeline/persistence/GapWriter.js b/src/matrix/room/timeline/persistence/GapWriter.js index ac265f9d..b1091afa 100644 --- a/src/matrix/room/timeline/persistence/GapWriter.js +++ b/src/matrix/room/timeline/persistence/GapWriter.js @@ -105,7 +105,7 @@ export class GapWriter { } } - async _storeEvents(events, startKey, direction, state, txn) { + async _storeEvents(events, startKey, direction, state, txn, log) { const entries = []; const updatedEntries = []; // events is in reverse chronological order for backwards pagination, @@ -123,12 +123,12 @@ export class GapWriter { txn.timelineEvents.insert(eventStorageEntry); const eventEntry = new EventEntry(eventStorageEntry, this._fragmentIdComparer); directionalAppend(entries, eventEntry, direction); - const updatedRelationTargetEntry = await this._relationWriter.writeRelation(eventEntry); + const updatedRelationTargetEntry = await this._relationWriter.writeRelation(eventEntry, txn, log); if (updatedRelationTargetEntry) { updatedEntries.push(updatedRelationTargetEntry); } } - return entries; + return {entries, updatedEntries}; } _findMember(userId, state, events, index, direction) { @@ -246,7 +246,7 @@ export class GapWriter { end = null; } // create entries for all events in chunk, add them to entries - const {entries, updatedEntries} = await this._storeEvents(nonOverlappingEvents, lastKey, direction, state, txn); + const {entries, updatedEntries} = await this._storeEvents(nonOverlappingEvents, lastKey, direction, state, txn, log); const fragments = await this._updateFragments(fragmentEntry, neighbourFragmentEntry, end, entries, txn); return {entries, updatedEntries, fragments}; diff --git a/src/matrix/room/timeline/persistence/RelationWriter.js b/src/matrix/room/timeline/persistence/RelationWriter.js index 67a78bb3..144ea40d 100644 --- a/src/matrix/room/timeline/persistence/RelationWriter.js +++ b/src/matrix/room/timeline/persistence/RelationWriter.js @@ -24,11 +24,11 @@ export class RelationWriter { } // this needs to happen again after decryption too for edits - async writeRelation(sourceEntry, txn) { + async writeRelation(sourceEntry, txn, log) { if (sourceEntry.relatedEventId) { const target = await txn.timelineEvents.getByEventId(this._roomId, sourceEntry.relatedEventId); if (target) { - if (this._applyRelation(sourceEntry, target)) { + if (this._applyRelation(sourceEntry, target, log)) { txn.timelineEvents.update(target); return new EventEntry(target, this._fragmentIdComparer); } @@ -37,15 +37,17 @@ export class RelationWriter { return; } - _applyRelation(sourceEntry, target) { + _applyRelation(sourceEntry, target, log) { if (sourceEntry.eventType === REDACTION_TYPE) { - return this._applyRedaction(sourceEntry.event, target.event); + return log.wrap("redact", log => this._applyRedaction(sourceEntry.event, target.event, log)); } else { return false; } } - _applyRedaction(redactionEvent, targetEvent) { + _applyRedaction(redactionEvent, targetEvent, log) { + log.set("redactionId", redactionEvent.event_id); + log.set("id", targetEvent.event_id); // TODO: should we make efforts to preserve the decrypted event type? // probably ok not to, as we'll show whatever is deleted as "deleted message" // reactions are the only thing that comes to mind, but we don't encrypt those (for now) diff --git a/src/matrix/room/timeline/persistence/SyncWriter.js b/src/matrix/room/timeline/persistence/SyncWriter.js index 8bf31ed2..671b944a 100644 --- a/src/matrix/room/timeline/persistence/SyncWriter.js +++ b/src/matrix/room/timeline/persistence/SyncWriter.js @@ -174,7 +174,7 @@ export class SyncWriter { txn.timelineEvents.insert(storageEntry); const entry = new EventEntry(storageEntry, this._fragmentIdComparer); entries.push(entry); - const updatedRelationTargetEntry = await this._relationWriter.writeRelation(entry); + const updatedRelationTargetEntry = await this._relationWriter.writeRelation(entry, txn, log); if (updatedRelationTargetEntry) { updatedEntries.push(updatedRelationTargetEntry); } @@ -246,7 +246,7 @@ export class SyncWriter { // members are available in the transaction await this._writeStateEvents(roomResponse, memberChanges, timeline?.limited, txn, log); const {currentKey, entries, updatedEntries} = - await this._writeTimeline(entries, updatedEntries, timeline, this._lastLiveKey, memberChanges, txn, log); + await this._writeTimeline(timeline, this._lastLiveKey, memberChanges, txn, log); log.set("memberChanges", memberChanges.size); return {entries, updatedEntries, newLiveKey: currentKey, memberChanges}; }