Rename RoomActivityTracker to ProtectedRoomActivityTracker

This commit is contained in:
gnuxie 2022-04-25 16:31:48 +01:00
parent a5a36a11cf
commit ba1ddccd04
2 changed files with 11 additions and 11 deletions

View File

@ -47,7 +47,7 @@ import { WebAPIs } from "./webapis/WebAPIs";
import { replaceRoomIdsWithPills } from "./utils"; import { replaceRoomIdsWithPills } from "./utils";
import RuleServer from "./models/RuleServer"; import RuleServer from "./models/RuleServer";
import { RoomMemberManager } from "./RoomMembers"; import { RoomMemberManager } from "./RoomMembers";
import { RoomActivityTracker } from "./queues/RoomActivityTracker"; import { ProtectedRoomActivityTracker } from "./queues/ProtectedRoomActivityTracker";
const levelToFn = { const levelToFn = {
[LogLevel.DEBUG.toString()]: LogService.debug, [LogLevel.DEBUG.toString()]: LogService.debug,
@ -94,7 +94,7 @@ export class Mjolnir {
private explicitlyProtectedRoomIds: string[] = []; private explicitlyProtectedRoomIds: string[] = [];
private unprotectedWatchedListRooms: string[] = []; private unprotectedWatchedListRooms: string[] = [];
private webapis: WebAPIs; private webapis: WebAPIs;
private roomActivityTracker: RoomActivityTracker; private protectedRoomActivityTracker: ProtectedRoomActivityTracker;
/** /**
* Adds a listener to the client that will automatically accept invitations. * Adds a listener to the client that will automatically accept invitations.
* @param {MatrixClient} client * @param {MatrixClient} client
@ -248,7 +248,7 @@ export class Mjolnir {
}); });
// Setup room activity watcher // Setup room activity watcher
this.roomActivityTracker = new RoomActivityTracker(client); this.protectedRoomActivityTracker = new ProtectedRoomActivityTracker(client);
// Setup Web APIs // Setup Web APIs
console.log("Creating Web APIs"); console.log("Creating Web APIs");
@ -308,7 +308,7 @@ export class Mjolnir {
for (const roomId of data['rooms']) { for (const roomId of data['rooms']) {
this.protectedRooms[roomId] = Permalinks.forRoom(roomId); this.protectedRooms[roomId] = Permalinks.forRoom(roomId);
this.explicitlyProtectedRoomIds.push(roomId); this.explicitlyProtectedRoomIds.push(roomId);
this.roomActivityTracker.addProtectedRoom(roomId); this.protectedRoomActivityTracker.addProtectedRoom(roomId);
} }
} }
} catch (e) { } catch (e) {
@ -388,7 +388,7 @@ export class Mjolnir {
public async addProtectedRoom(roomId: string) { public async addProtectedRoom(roomId: string) {
this.protectedRooms[roomId] = Permalinks.forRoom(roomId); this.protectedRooms[roomId] = Permalinks.forRoom(roomId);
this.roomJoins.addRoom(roomId); this.roomJoins.addRoom(roomId);
this.roomActivityTracker.addProtectedRoom(roomId); this.protectedRoomActivityTracker.addProtectedRoom(roomId);
const unprotectedIdx = this.unprotectedWatchedListRooms.indexOf(roomId); const unprotectedIdx = this.unprotectedWatchedListRooms.indexOf(roomId);
if (unprotectedIdx >= 0) this.unprotectedWatchedListRooms.splice(unprotectedIdx, 1); if (unprotectedIdx >= 0) this.unprotectedWatchedListRooms.splice(unprotectedIdx, 1);
@ -409,7 +409,7 @@ export class Mjolnir {
public async removeProtectedRoom(roomId: string) { public async removeProtectedRoom(roomId: string) {
delete this.protectedRooms[roomId]; delete this.protectedRooms[roomId];
this.roomJoins.removeRoom(roomId); this.roomJoins.removeRoom(roomId);
this.roomActivityTracker.removeProtectedRoom(roomId); this.protectedRoomActivityTracker.removeProtectedRoom(roomId);
const idx = this.explicitlyProtectedRoomIds.indexOf(roomId); const idx = this.explicitlyProtectedRoomIds.indexOf(roomId);
if (idx >= 0) this.explicitlyProtectedRoomIds.splice(idx, 1); if (idx >= 0) this.explicitlyProtectedRoomIds.splice(idx, 1);
@ -433,7 +433,7 @@ export class Mjolnir {
// Remove every room id that we have joined from `this.protectedRooms`. // Remove every room id that we have joined from `this.protectedRooms`.
for (const roomId of this.protectedJoinedRoomIds) { for (const roomId of this.protectedJoinedRoomIds) {
delete this.protectedRooms[roomId]; delete this.protectedRooms[roomId];
this.roomActivityTracker.removeProtectedRoom(roomId); this.protectedRoomActivityTracker.removeProtectedRoom(roomId);
if (!joinedRoomIdsSet.has(roomId)) { if (!joinedRoomIdsSet.has(roomId)) {
this.roomJoins.removeRoom(roomId); this.roomJoins.removeRoom(roomId);
} }
@ -442,7 +442,7 @@ export class Mjolnir {
// Add all joined rooms back to the permalink object // Add all joined rooms back to the permalink object
for (const roomId of joinedRoomIds) { for (const roomId of joinedRoomIds) {
this.protectedRooms[roomId] = Permalinks.forRoom(roomId); this.protectedRooms[roomId] = Permalinks.forRoom(roomId);
this.roomActivityTracker.addProtectedRoom(roomId); this.protectedRoomActivityTracker.addProtectedRoom(roomId);
if (!oldRoomIdsSet.has(roomId)) { if (!oldRoomIdsSet.has(roomId)) {
this.roomJoins.addRoom(roomId); this.roomJoins.addRoom(roomId);
} }
@ -701,7 +701,7 @@ export class Mjolnir {
private applyUnprotectedRooms() { private applyUnprotectedRooms() {
for (const roomId of this.unprotectedWatchedListRooms) { for (const roomId of this.unprotectedWatchedListRooms) {
delete this.protectedRooms[roomId]; delete this.protectedRooms[roomId];
this.roomActivityTracker.removeProtectedRoom(roomId); this.protectedRoomActivityTracker.removeProtectedRoom(roomId);
} }
} }
@ -825,7 +825,7 @@ export class Mjolnir {
* @returns The protected rooms ordered by the most recently active first. * @returns The protected rooms ordered by the most recently active first.
*/ */
public protectedRoomsByActivity(): string[] { public protectedRoomsByActivity(): string[] {
return this.roomActivityTracker.protectedRoomsByActivity(); return this.protectedRoomActivityTracker.protectedRoomsByActivity();
} }
/** /**

View File

@ -23,7 +23,7 @@ import { MatrixClient } from "matrix-bot-sdk";
* See https://github.com/matrix-org/matrix-react-sdk/blob/8a0398b632dff1a5f6cfd4bf95d78854aeadc60e/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts * See https://github.com/matrix-org/matrix-react-sdk/blob/8a0398b632dff1a5f6cfd4bf95d78854aeadc60e/src/stores/room-list/algorithms/tag-sorting/RecentAlgorithm.ts
* *
*/ */
export class RoomActivityTracker { export class ProtectedRoomActivityTracker {
private protectedRoomActivities = new Map<string/*room id*/, number/*last event timestamp*/>(); private protectedRoomActivities = new Map<string/*room id*/, number/*last event timestamp*/>();
/** /**
* A slot to cache the rooms for `protectedRoomsByActivity` ordered so the most recently active room is first. * A slot to cache the rooms for `protectedRoomsByActivity` ordered so the most recently active room is first.