mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
stronger check that message is edit
This commit is contained in:
parent
6f2773533f
commit
bde03c2a75
@ -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
|
||||
|
@ -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;
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user