Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add users who activate mention spam protection to auto-redact list #541

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/protections/MentionSpam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 12 additions & 0 deletions test/integration/mentionSpamProtectionTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
})
});
});
Loading