From 150f58a6b3134c1562e0f13c3de2a89dbed62559 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 16 Jun 2021 18:00:50 +0200 Subject: [PATCH] don't aggregate relations on redacted events --- src/matrix/room/common.js | 4 ++++ src/matrix/room/timeline/entries/EventEntry.js | 4 ++-- src/matrix/room/timeline/persistence/RelationWriter.js | 6 +++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/matrix/room/common.js b/src/matrix/room/common.js index 721160e6..b009a89c 100644 --- a/src/matrix/room/common.js +++ b/src/matrix/room/common.js @@ -21,3 +21,7 @@ export function getPrevContentFromStateEvent(event) { } export const REDACTION_TYPE = "m.room.redaction"; + +export function isRedacted(event) { + return !!event?.unsigned?.redacted_because; +} diff --git a/src/matrix/room/timeline/entries/EventEntry.js b/src/matrix/room/timeline/entries/EventEntry.js index 2aa9cba0..3a6889f7 100644 --- a/src/matrix/room/timeline/entries/EventEntry.js +++ b/src/matrix/room/timeline/entries/EventEntry.js @@ -15,7 +15,7 @@ limitations under the License. */ import {BaseEventEntry} from "./BaseEventEntry.js"; -import {getPrevContentFromStateEvent} from "../../common.js"; +import {getPrevContentFromStateEvent, isRedacted} from "../../common.js"; import {getRelatedEventId} from "../relations.js"; export class EventEntry extends BaseEventEntry { @@ -115,7 +115,7 @@ export class EventEntry extends BaseEventEntry { } get isRedacted() { - return super.isRedacted || !!this._eventEntry.event.unsigned?.redacted_because; + return super.isRedacted || isRedacted(this._eventEntry.event); } get redactionReason() { diff --git a/src/matrix/room/timeline/persistence/RelationWriter.js b/src/matrix/room/timeline/persistence/RelationWriter.js index 13b0014d..853dcb0b 100644 --- a/src/matrix/room/timeline/persistence/RelationWriter.js +++ b/src/matrix/room/timeline/persistence/RelationWriter.js @@ -15,7 +15,7 @@ limitations under the License. */ import {EventEntry} from "../entries/EventEntry.js"; -import {REDACTION_TYPE} from "../../common.js"; +import {REDACTION_TYPE, isRedacted} from "../../common.js"; import {ANNOTATION_RELATION_TYPE, getRelation} from "../relations.js"; export class RelationWriter { @@ -58,7 +58,7 @@ export class RelationWriter { const result = await this.writeRelation(sourceEntry, txn, log); // when back-paginating, it can also happen that we've received relations // for this event before, which now upon receiving the target need to be aggregated. - if (direction.isBackward) { + if (direction.isBackward && !isRedacted(storageEntry.event)) { const relations = await txn.timelineRelations.getAllForTarget(this._roomId, sourceEntry.id); if (relations.length) { for (const r of relations) { @@ -99,7 +99,7 @@ export class RelationWriter { }); } else { const relation = getRelation(sourceEntry.event); - if (relation) { + if (relation && !isRedacted(targetStorageEntry.event)) { const relType = relation.rel_type; if (relType === ANNOTATION_RELATION_TYPE) { const aggregated = log.wrap("react", log => {