From 93861950bab1059fa2fe21e9eab8d21a16a278fb Mon Sep 17 00:00:00 2001 From: gnuxie Date: Mon, 31 Oct 2022 17:55:57 +0000 Subject: [PATCH] Clear internal queues within protections when unban happens. https://github.com/matrix-org/mjolnir/issues/393 --- src/commands/UnbanBanCommand.ts | 13 ++++++++++--- src/queues/UnlistedUserRedactionQueue.ts | 4 ++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/commands/UnbanBanCommand.ts b/src/commands/UnbanBanCommand.ts index 9fa061f..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,8 +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); } - } else if (USER_RULE_TYPES.includes(bits.ruleType!) && bits.reason === 'false') { - await mjolnir.managementRoomOutput.logMessage(LogLevel.WARN, "UnbanBanCommand", "Running unban without `unban true` will not override existing room level bans"); + }; + + 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); }