Feedback from review.

This commit is contained in:
gnuxie 2022-04-25 16:29:31 +01:00
parent 8ee8d37c3f
commit a5a36a11cf
2 changed files with 6 additions and 5 deletions

View File

@ -85,7 +85,7 @@ export class Mjolnir {
private eventRedactionQueue = new EventRedactionQueue();
private automaticRedactionReasons: MatrixGlob[] = [];
/**
* Every room that we are joined to except the management room.
* Every room that we are joined to except the management room. Used to implement `config.protectAllJoinedRooms`.
*/
private protectedJoinedRoomIds: string[] = [];
/**
@ -177,7 +177,7 @@ export class Mjolnir {
public readonly managementRoomId: string,
/*
* All the rooms that Mjolnir is protecting and their permalinks.
* If `` is specified, then this will be all joined rooms with watched banlists we can't protect removed.
* If `config.protectAllJoinedRooms` is specified, then `protectedRooms` will be all joined rooms except watched banlists that we can't protect (because they aren't curated by us).
*/
public readonly protectedRooms: { [roomId: string]: string },
private banLists: BanList[],

View File

@ -18,14 +18,15 @@ import { MatrixClient } from "matrix-bot-sdk";
/**
* Used to keep track of protected rooms so they are always ordered for activity.
*
* We use the same method as Element web for this, the major disadvantage being that we sort each time we access the rooms.
* We use the same method as Element web for this, the major disadvantage being that we sort on each access to the room list (sort by most recently active first).
* We have tried to mitigate this by caching the sorted list until the activity in rooms changes again.
* See https://github.com/matrix-org/matrix-react-sdk/blob/8a0398b632dff1a5f6cfd4bf95d78854aeadc60e/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts
*
*/
export class RoomActivityTracker {
private protectedRoomActivities = new Map<string/*room id*/, number/*last event timestamp*/>();
/**
* A slot to cache the ordered rooms for `protectedRoomsByActivity`.
* A slot to cache the rooms for `protectedRoomsByActivity` ordered so the most recently active room is first.
*/
private activeRoomsCache: null|string[] = null
constructor(client: MatrixClient) {
@ -37,7 +38,7 @@ export class RoomActivityTracker {
* @param roomId The room Mjolnir is now protecting.
*/
public addProtectedRoom(roomId: string): void {
this.protectedRoomActivities.set(roomId, 0);
this.protectedRoomActivities.set(roomId, /* epoch */ 0);
}
/**