This commit is contained in:
gnuxie 2022-11-07 09:37:20 +00:00
parent fb52e3dcb2
commit 58e8174378
3 changed files with 25 additions and 1 deletions

View File

@ -384,6 +384,19 @@ export class Mjolnir {
this.protectedRoomsTracker.removeProtectedRoom(roomId);
}
public async addProtectedSpace(roomId: string): Promise<void> {
await this.protectedRoomsConfig.addProtectedSpace(roomId);
await this.protectSpace(roomId);
}
private async protectSpace(roomId: string): Promise<void> {
// create a ProtectedSpace and keep that somewhere,
// protected space could use ProtectedRoomSet for all its rooms.
// don't bother with recursively following spaces yet, but we probably need something like
// m.space.parent for that to work properly since anyone can add any room to spaces.
//
}
/**
* Resynchronize the protected rooms with rooms that the mjolnir user is joined to.
* This is to implement `config.protectAllJoinedRooms` functionality.

View File

@ -19,6 +19,16 @@ import { extractRequestError, LogService, MatrixClient, Permalinks } from "matri
import { IConfig } from "./config";
const PROTECTED_ROOMS_EVENT_TYPE = "org.matrix.mjolnir.protected_rooms";
interface ProtectedRoomsAccountData {
rooms: string[],
spaces: [
{
room_id: string,
recursive: boolean,
}
]
}
/**
* Manages the set of rooms that the user has EXPLICITLY asked to be protected.
*/
@ -64,7 +74,7 @@ export default class ProtectedRoomsConfig {
public async loadProtectedRoomsFromAccountData(): Promise<void> {
LogService.debug("ProtectedRoomsConfig", "Loading protected rooms...");
try {
const data: { rooms?: string[] } | null = await this.client.getAccountData(PROTECTED_ROOMS_EVENT_TYPE);
const data: ProtectedRoomsAccountData | null = await this.client.getAccountData(PROTECTED_ROOMS_EVENT_TYPE);
if (data && data['rooms']) {
for (const roomId of data['rooms']) {
this.explicitlyProtectedRooms.add(roomId);

1
src/ProtectedSpace.ts Normal file
View File

@ -0,0 +1 @@
import { Space } from "matrix-bot-sdk";