Skip to content

Commit

Permalink
stronger check that message is edit
Browse files Browse the repository at this point in the history
  • Loading branch information
H-Shay committed Jul 26, 2024
1 parent 6f27735 commit bde03c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/protections/MessageIsMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/integration/protectionSettingsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -190,3 +190,4 @@ describe("Test: Protection settings", function() {
await reply2;
});
});

0 comments on commit bde03c2

Please sign in to comment.