stronger check that message is edit

This commit is contained in:
H. Shay 2024-07-26 11:17:05 -07:00
parent 6f2773533f
commit bde03c2a75
2 changed files with 7 additions and 3 deletions

View File

@ -36,10 +36,13 @@ export class MessageIsMedia extends Protection {
public async handleEvent(mjolnir: Mjolnir, roomId: string, event: any): Promise<any> {
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('<img');
const isMedia = msgtype === 'm.image' || msgtype === 'm.video' || msgtype === 'm.sticker' || formattedBody.toLowerCase().includes('<img');
if (isMedia) {
await mjolnir.managementRoomOutput.logMessage(LogLevel.WARN, "MessageIsMedia", `Redacting event from ${event['sender']} for posting an image/video. ${Permalinks.forEvent(roomId, event['event_id'], [new UserID(await mjolnir.client.getUserId()).domain])}`);
// Redact the event

View File

@ -179,7 +179,7 @@ describe("Test: Protection settings", function() {
});
await reply;
await client.sendMessage(room, {"m.new_content": {msgtype: "m.image", body: ""}, body: "", msgtype: "m.text"})
await client.sendMessage(room, {body: "", msgtype: "m.text", "m.new_content": {msgtype: "m.image", body: ""}, "m.relates_to": {"rel_type": "m.replace"}})
let reply2 = () => 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;
});
});