From bde03c2a756d7dd092f94a4ae0dab314484ef1f6 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Fri, 26 Jul 2024 11:17:05 -0700 Subject: [PATCH] stronger check that message is edit --- src/protections/MessageIsMedia.ts | 7 +++++-- test/integration/protectionSettingsTest.ts | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/protections/MessageIsMedia.ts b/src/protections/MessageIsMedia.ts index bf27aac..791db1a 100644 --- a/src/protections/MessageIsMedia.ts +++ b/src/protections/MessageIsMedia.ts @@ -36,10 +36,13 @@ export class MessageIsMedia extends Protection { public async handleEvent(mjolnir: Mjolnir, roomId: string, event: any): Promise { if (event['type'] === 'm.room.message') { let content = event['content'] || {}; - content = content?.["m.new_content"] ?? content; + const relation = content["m.relates_to"] + if (relation && relation["rel_type"] === "m.replace") { + content = content?.["m.new_content"] ?? content; + } const msgtype = content['msgtype'] || 'm.text'; const formattedBody = content['formatted_body'] || ''; - let isMedia = msgtype === 'm.image' || msgtype === 'm.video' || msgtype === 'm.sticker' || formattedBody.toLowerCase().includes(' new Promise((resolve, reject) => { client.on('room.message', noticeListener(this.mjolnir.managementRoomId, (event) => { if (event.content.body.includes("Redacting event")) { @@ -190,3 +190,4 @@ describe("Test: Protection settings", function() { await reply2; }); }); +