mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
Rename RoomActivityTracker to ProtectedRoomActivityTracker
This commit is contained in:
parent
a5a36a11cf
commit
ba1ddccd04
@ -47,7 +47,7 @@ import { WebAPIs } from "./webapis/WebAPIs";
|
||||
import { replaceRoomIdsWithPills } from "./utils";
|
||||
import RuleServer from "./models/RuleServer";
|
||||
import { RoomMemberManager } from "./RoomMembers";
|
||||
import { RoomActivityTracker } from "./queues/RoomActivityTracker";
|
||||
import { ProtectedRoomActivityTracker } from "./queues/ProtectedRoomActivityTracker";
|
||||
|
||||
const levelToFn = {
|
||||
[LogLevel.DEBUG.toString()]: LogService.debug,
|
||||
@ -94,7 +94,7 @@ export class Mjolnir {
|
||||
private explicitlyProtectedRoomIds: string[] = [];
|
||||
private unprotectedWatchedListRooms: string[] = [];
|
||||
private webapis: WebAPIs;
|
||||
private roomActivityTracker: RoomActivityTracker;
|
||||
private protectedRoomActivityTracker: ProtectedRoomActivityTracker;
|
||||
/**
|
||||
* Adds a listener to the client that will automatically accept invitations.
|
||||
* @param {MatrixClient} client
|
||||
@ -248,7 +248,7 @@ export class Mjolnir {
|
||||
});
|
||||
|
||||
// Setup room activity watcher
|
||||
this.roomActivityTracker = new RoomActivityTracker(client);
|
||||
this.protectedRoomActivityTracker = new ProtectedRoomActivityTracker(client);
|
||||
|
||||
// Setup Web APIs
|
||||
console.log("Creating Web APIs");
|
||||
@ -308,7 +308,7 @@ export class Mjolnir {
|
||||
for (const roomId of data['rooms']) {
|
||||
this.protectedRooms[roomId] = Permalinks.forRoom(roomId);
|
||||
this.explicitlyProtectedRoomIds.push(roomId);
|
||||
this.roomActivityTracker.addProtectedRoom(roomId);
|
||||
this.protectedRoomActivityTracker.addProtectedRoom(roomId);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
@ -388,7 +388,7 @@ export class Mjolnir {
|
||||
public async addProtectedRoom(roomId: string) {
|
||||
this.protectedRooms[roomId] = Permalinks.forRoom(roomId);
|
||||
this.roomJoins.addRoom(roomId);
|
||||
this.roomActivityTracker.addProtectedRoom(roomId);
|
||||
this.protectedRoomActivityTracker.addProtectedRoom(roomId);
|
||||
|
||||
const unprotectedIdx = this.unprotectedWatchedListRooms.indexOf(roomId);
|
||||
if (unprotectedIdx >= 0) this.unprotectedWatchedListRooms.splice(unprotectedIdx, 1);
|
||||
@ -409,7 +409,7 @@ export class Mjolnir {
|
||||
public async removeProtectedRoom(roomId: string) {
|
||||
delete this.protectedRooms[roomId];
|
||||
this.roomJoins.removeRoom(roomId);
|
||||
this.roomActivityTracker.removeProtectedRoom(roomId);
|
||||
this.protectedRoomActivityTracker.removeProtectedRoom(roomId);
|
||||
|
||||
const idx = this.explicitlyProtectedRoomIds.indexOf(roomId);
|
||||
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`.
|
||||
for (const roomId of this.protectedJoinedRoomIds) {
|
||||
delete this.protectedRooms[roomId];
|
||||
this.roomActivityTracker.removeProtectedRoom(roomId);
|
||||
this.protectedRoomActivityTracker.removeProtectedRoom(roomId);
|
||||
if (!joinedRoomIdsSet.has(roomId)) {
|
||||
this.roomJoins.removeRoom(roomId);
|
||||
}
|
||||
@ -442,7 +442,7 @@ export class Mjolnir {
|
||||
// Add all joined rooms back to the permalink object
|
||||
for (const roomId of joinedRoomIds) {
|
||||
this.protectedRooms[roomId] = Permalinks.forRoom(roomId);
|
||||
this.roomActivityTracker.addProtectedRoom(roomId);
|
||||
this.protectedRoomActivityTracker.addProtectedRoom(roomId);
|
||||
if (!oldRoomIdsSet.has(roomId)) {
|
||||
this.roomJoins.addRoom(roomId);
|
||||
}
|
||||
@ -701,7 +701,7 @@ export class Mjolnir {
|
||||
private applyUnprotectedRooms() {
|
||||
for (const roomId of this.unprotectedWatchedListRooms) {
|
||||
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.
|
||||
*/
|
||||
public protectedRoomsByActivity(): string[] {
|
||||
return this.roomActivityTracker.protectedRoomsByActivity();
|
||||
return this.protectedRoomActivityTracker.protectedRoomsByActivity();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
*
|
||||
*/
|
||||
export class RoomActivityTracker {
|
||||
export class ProtectedRoomActivityTracker {
|
||||
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.
|
Loading…
Reference in New Issue
Block a user