From fb52e3dcb2dbf9afe0f7a22ef923202ba4c0fedc Mon Sep 17 00:00:00 2001 From: Gnuxie <50846879+Gnuxie@users.noreply.github.com> Date: Mon, 7 Nov 2022 11:28:59 +0000 Subject: [PATCH] Improve the clarity of the unban command (#402) Also fix a years long bug where the Flooding/Media protection wouldn't stop redacting users Closes #393 Closes #394 * Warn about room level bans when using unban https://github.com/matrix-org/mjolnir/issues/394 * Clear internal queues within protections when unban happens. https://github.com/matrix-org/mjolnir/issues/393 --- src/commands/UnbanBanCommand.ts | 11 ++++++++++- src/queues/UnlistedUserRedactionQueue.ts | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/commands/UnbanBanCommand.ts b/src/commands/UnbanBanCommand.ts index ad7d7c7..b5c5b90 100644 --- a/src/commands/UnbanBanCommand.ts +++ b/src/commands/UnbanBanCommand.ts @@ -129,7 +129,7 @@ export async function execUnbanCommand(roomId: string, event: any, mjolnir: Mjol await bits.list!.unbanEntity(bits.ruleType!, bits.entity); - if (USER_RULE_TYPES.includes(bits.ruleType!) && bits.reason === 'true') { + const unbanUserFromRooms = async () => { const rule = new MatrixGlob(bits.entity); await mjolnir.managementRoomOutput.logMessage(LogLevel.INFO, "UnbanBanCommand", "Unbanning users that match glob: " + bits.entity); let unbannedSomeone = false; @@ -157,6 +157,15 @@ export async function execUnbanCommand(roomId: string, event: any, mjolnir: Mjol await mjolnir.managementRoomOutput.logMessage(LogLevel.DEBUG, "UnbanBanCommand", `Syncing lists to ensure no users were accidentally unbanned`); await mjolnir.protectedRoomsTracker.syncLists(mjolnir.config.verboseLogging); } + }; + + if (USER_RULE_TYPES.includes(bits.ruleType!)) { + mjolnir.unlistedUserRedactionHandler.removeUser(bits.entity); + if (bits.reason === 'true') { + await unbanUserFromRooms(); + } else { + await mjolnir.managementRoomOutput.logMessage(LogLevel.WARN, "UnbanBanCommand", "Running unban without `unban true` will not override existing room level bans"); + } } await mjolnir.client.unstableApis.addReactionToEvent(roomId, event['event_id'], '✅'); diff --git a/src/queues/UnlistedUserRedactionQueue.ts b/src/queues/UnlistedUserRedactionQueue.ts index 9c50baa..ee10fae 100644 --- a/src/queues/UnlistedUserRedactionQueue.ts +++ b/src/queues/UnlistedUserRedactionQueue.ts @@ -33,6 +33,10 @@ export class UnlistedUserRedactionQueue { this.usersToRedact.add(userId); } + public removeUser(userId: string) { + this.usersToRedact.delete(userId); + } + public isUserQueued(userId: string): boolean { return this.usersToRedact.has(userId); }