Rename AutomaticRedactionQueue to UnlistedUserRedactionQueue.

This seems to be a more descriptive name and it also doesn't clash
with the new redaction queue.
This commit is contained in:
gnuxie 2021-09-14 14:36:53 +01:00
parent c949d26582
commit 2889599eb2
4 changed files with 12 additions and 15 deletions

View File

@ -34,7 +34,7 @@ import { logMessage } from "./LogProxy";
import ErrorCache, { ERROR_KIND_FATAL, ERROR_KIND_PERMISSION } from "./ErrorCache"; import ErrorCache, { ERROR_KIND_FATAL, ERROR_KIND_PERMISSION } from "./ErrorCache";
import { IProtection } from "./protections/IProtection"; import { IProtection } from "./protections/IProtection";
import { PROTECTIONS } from "./protections/protections"; import { PROTECTIONS } from "./protections/protections";
import { AutomaticRedactionQueue } from "./queues/AutomaticRedactionQueue"; import { UnlistedUserRedactionQueue } from "./queues/UnlistedUserRedactionQueue";
import { Healthz } from "./health/healthz"; import { Healthz } from "./health/healthz";
import { EventRedactionQueue, RedactUserInRoom } from "./queues/EventRedactionQueue"; import { EventRedactionQueue, RedactUserInRoom } from "./queues/EventRedactionQueue";
@ -54,7 +54,7 @@ export class Mjolnir {
private localpart: string; private localpart: string;
private currentState: string = STATE_NOT_STARTED; private currentState: string = STATE_NOT_STARTED;
private protections: IProtection[] = []; private protections: IProtection[] = [];
private spamRedactionQueue = new AutomaticRedactionQueue(); private unlistedUserRedactionQueue = new UnlistedUserRedactionQueue();
private eventRedactionQueue = new EventRedactionQueue(); private eventRedactionQueue = new EventRedactionQueue();
private automaticRedactionReasons: MatrixGlob[] = []; private automaticRedactionReasons: MatrixGlob[] = [];
private protectedJoinedRoomIds: string[] = []; private protectedJoinedRoomIds: string[] = [];
@ -140,8 +140,8 @@ export class Mjolnir {
return this.protections; return this.protections;
} }
public get redactionHandler(): AutomaticRedactionQueue { public get unlistedUserRedactionHandler(): UnlistedUserRedactionQueue {
return this.spamRedactionQueue; return this.unlistedUserRedactionQueue;
} }
public get automaticRedactGlobs(): MatrixGlob[] { 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 // Run the event handlers - we always run this after protections so that the protections
// can flag the event for redaction. // 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'] === '') { if (event['type'] === 'm.room.power_levels' && event['state_key'] === '') {
// power levels were updated - recheck permissions // 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) { public queueRedactUserMessagesIn(userId: string, roomId: string) {
this.eventRedactionQueue.add(new RedactUserInRoom(userId, roomId)); this.eventRedactionQueue.add(new RedactUserInRoom(userId, roomId));
} }

View File

@ -65,7 +65,7 @@ export class BasicFlooding implements IProtection {
} }
if (this.recentlyBanned.includes(event['sender'])) return; // already handled (will be redacted) 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 this.recentlyBanned.push(event['sender']); // flag to reduce spam
// Redact all the things the user said too // Redact all the things the user said too

View File

@ -59,7 +59,7 @@ export class FirstMessageIsImage implements IProtection {
} }
if (this.recentlyBanned.includes(event['sender'])) return; // already handled (will be redacted) 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 this.recentlyBanned.push(event['sender']); // flag to reduce spam
// Redact the event // Redact the event

View File

@ -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 See the License for the specific language governing permissions and
limitations under the License. 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 { extractRequestError, LogLevel, LogService, MatrixClient, Permalinks } from "matrix-bot-sdk";
import { logMessage } from "../LogProxy"; import { logMessage } from "../LogProxy";
import config from "../config"; 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<string> = new Set<string>(); private usersToRedact: Set<string> = new Set<string>();
constructor() { constructor() {