diff --git a/src/Mjolnir.ts b/src/Mjolnir.ts index e02eec8..1626d9b 100644 --- a/src/Mjolnir.ts +++ b/src/Mjolnir.ts @@ -34,7 +34,7 @@ import { logMessage } from "./LogProxy"; import ErrorCache, { ERROR_KIND_FATAL, ERROR_KIND_PERMISSION } from "./ErrorCache"; import { IProtection } from "./protections/IProtection"; import { PROTECTIONS } from "./protections/protections"; -import { AutomaticRedactionQueue } from "./queues/AutomaticRedactionQueue"; +import { UnlistedUserRedactionQueue } from "./queues/UnlistedUserRedactionQueue"; import { Healthz } from "./health/healthz"; import { EventRedactionQueue, RedactUserInRoom } from "./queues/EventRedactionQueue"; @@ -54,7 +54,7 @@ export class Mjolnir { private localpart: string; private currentState: string = STATE_NOT_STARTED; private protections: IProtection[] = []; - private spamRedactionQueue = new AutomaticRedactionQueue(); + private unlistedUserRedactionQueue = new UnlistedUserRedactionQueue(); private eventRedactionQueue = new EventRedactionQueue(); private automaticRedactionReasons: MatrixGlob[] = []; private protectedJoinedRoomIds: string[] = []; @@ -140,8 +140,8 @@ export class Mjolnir { return this.protections; } - public get redactionHandler(): AutomaticRedactionQueue { - return this.spamRedactionQueue; + public get unlistedUserRedactionHandler(): UnlistedUserRedactionQueue { + return this.unlistedUserRedactionQueue; } public get automaticRedactGlobs(): MatrixGlob[] { @@ -581,7 +581,7 @@ export class Mjolnir { // Run the event handlers - we always run this after protections so that the protections // can flag the event for redaction. - await this.spamRedactionQueue.handleEvent(roomId, event, this.client); + await this.unlistedUserRedactionHandler.handleEvent(roomId, event, this.client); if (event['type'] === 'm.room.power_levels' && event['state_key'] === '') { // power levels were updated - recheck permissions @@ -667,9 +667,6 @@ export class Mjolnir { }); } - // This naming is horrible and clashes with the other redaction queue which isn't - // really the same thing. The old one is more about an ongoing user who we haven't - // banned, whereas this one is about redaction of users who aren't active. public queueRedactUserMessagesIn(userId: string, roomId: string) { this.eventRedactionQueue.add(new RedactUserInRoom(userId, roomId)); } diff --git a/src/protections/BasicFlooding.ts b/src/protections/BasicFlooding.ts index 92d6a86..017b568 100644 --- a/src/protections/BasicFlooding.ts +++ b/src/protections/BasicFlooding.ts @@ -65,7 +65,7 @@ export class BasicFlooding implements IProtection { } if (this.recentlyBanned.includes(event['sender'])) return; // already handled (will be redacted) - mjolnir.redactionHandler.addUser(event['sender']); + mjolnir.unlistedUserRedactionHandler.addUser(event['sender']); this.recentlyBanned.push(event['sender']); // flag to reduce spam // Redact all the things the user said too diff --git a/src/protections/FirstMessageIsImage.ts b/src/protections/FirstMessageIsImage.ts index c42a63c..89a7865 100644 --- a/src/protections/FirstMessageIsImage.ts +++ b/src/protections/FirstMessageIsImage.ts @@ -59,7 +59,7 @@ export class FirstMessageIsImage implements IProtection { } if (this.recentlyBanned.includes(event['sender'])) return; // already handled (will be redacted) - mjolnir.redactionHandler.addUser(event['sender']); + mjolnir.unlistedUserRedactionHandler.addUser(event['sender']); this.recentlyBanned.push(event['sender']); // flag to reduce spam // Redact the event diff --git a/src/queues/AutomaticRedactionQueue.ts b/src/queues/UnlistedUserRedactionQueue.ts similarity index 86% rename from src/queues/AutomaticRedactionQueue.ts rename to src/queues/UnlistedUserRedactionQueue.ts index 63a5474..083df87 100644 --- a/src/queues/AutomaticRedactionQueue.ts +++ b/src/queues/UnlistedUserRedactionQueue.ts @@ -13,15 +13,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -//// NOTE: This is a queue of users whose events should be redacted -////////// Not a queue of events to be redacted. -////////// This is also unrelated to the AutomaticRedactionReasons. -////////// It is as of writing only used by the flood/spam protections. import { extractRequestError, LogLevel, LogService, MatrixClient, Permalinks } from "matrix-bot-sdk"; import { logMessage } from "../LogProxy"; import config from "../config"; -export class AutomaticRedactionQueue { +/** + * This is used to redact new events from users who are not banned from a watched list, but have been flagged + * for redaction by the flooding or image protection. + */ +export class UnlistedUserRedactionQueue { private usersToRedact: Set = new Set(); constructor() {