From 6b5f4aa0a9c16fa0b3a5252ad5e60802adb05ac0 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 5 May 2022 07:14:23 +0100 Subject: [PATCH] Prune both clear & wire content on redaction (#2346) --- spec/unit/models/event.spec.ts | 27 +++++++++++++++++++++++++++ src/models/event.ts | 22 ++++++++++------------ 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/spec/unit/models/event.spec.ts b/spec/unit/models/event.spec.ts index f1a8969ddfd..7f2b263137c 100644 --- a/spec/unit/models/event.spec.ts +++ b/spec/unit/models/event.spec.ts @@ -57,4 +57,31 @@ describe('MatrixEvent', () => { expect(a.toSnapshot().isEquivalentTo(a)).toBe(true); expect(a.toSnapshot().isEquivalentTo(b)).toBe(false); }); + + it("should prune clearEvent when being redacted", () => { + const ev = new MatrixEvent({ + type: "m.room.message", + content: { + body: "Test", + }, + event_id: "$event1:server", + }); + + expect(ev.getContent().body).toBe("Test"); + expect(ev.getWireContent().body).toBe("Test"); + ev.makeEncrypted("m.room.encrypted", { ciphertext: "xyz" }, "", ""); + expect(ev.getContent().body).toBe("Test"); + expect(ev.getWireContent().body).toBeUndefined(); + expect(ev.getWireContent().ciphertext).toBe("xyz"); + + const redaction = new MatrixEvent({ + type: "m.room.redaction", + redacts: ev.getId(), + }); + + ev.makeRedacted(redaction); + expect(ev.getContent().body).toBeUndefined(); + expect(ev.getWireContent().body).toBeUndefined(); + expect(ev.getWireContent().ciphertext).toBeUndefined(); + }); }); diff --git a/src/models/event.ts b/src/models/event.ts index bcfaab9c658..227036be5e7 100644 --- a/src/models/event.ts +++ b/src/models/event.ts @@ -1112,23 +1112,21 @@ export class MatrixEvent extends TypedEventEmitter