diff --git a/src/protections/MentionSpam.ts b/src/protections/MentionSpam.ts index 10286c27..a14fa14e 100644 --- a/src/protections/MentionSpam.ts +++ b/src/protections/MentionSpam.ts @@ -104,6 +104,7 @@ export class MentionSpam extends Protection { // Redact the event if (!mjolnir.config.noop) { await mjolnir.client.redactEvent(roomId, event['event_id'], "Message was detected as spam."); + mjolnir.unlistedUserRedactionHandler.addUser(event['sender']); } else { await mjolnir.managementRoomOutput.logMessage(LogLevel.WARN, "MentionSpam", `Tried to redact ${event['event_id']} in ${roomId} but Mjolnir is running in no-op mode`, roomId); } diff --git a/test/integration/mentionSpamProtectionTest.ts b/test/integration/mentionSpamProtectionTest.ts index 328508b1..3cb7e8db 100644 --- a/test/integration/mentionSpamProtectionTest.ts +++ b/test/integration/mentionSpamProtectionTest.ts @@ -107,5 +107,17 @@ describe("Test: Mention spam protection", function () { const fetchedDisplaynameEvent = await client.getEvent(room, messageWithDisplaynameMentions); assert.equal(Object.keys(fetchedDisplaynameEvent.content).length, 0, "This event should have been redacted"); + + // send messages after activating protection, they should be auto-redacted + const messages = []; + for (let i = 0; i < 10; i++) { + let nextMessage = await client.sendText(room, `hello${i}`); + messages.push(nextMessage) + } + + messages.forEach(async (eventID) => { + await client.getEvent(room, eventID); + assert.equal(Object.keys(fetchedDisplaynameEvent.content).length, 0, "This event should have been redacted"); + }) }); }); \ No newline at end of file