mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 01:36:06 -04:00
77ad40e27a
* Attempt to factor out protected rooms from Mjolnir. This is useful to the appservice because it means we don't have to wrap a Mjolnir that is designed to sync. It's also useful if we later on want to have specific settings per space. It's also just a nice seperation between Mjolnir's needs while syncing via client-server and the behaviour of syncing policy rooms. ### Things that have changed - `ErrorCache` no longer a static class (phew), gets used by `ProtectedRooms`. - `ManagementRoomOutput` class gets created to handle logging back to the management room. - Responsibilities for syncing member bans and server ACL are handled by `ProtectedRooms`. - Responsibilities for watched lists should be moved to `ProtectedRooms` if they haven't been. - `EventRedactionQueue` is moved to `ProtectedRooms` since this needs to happen after member bans. - ApplyServerAcls moved to `ProtectedRooms` - ApplyMemberBans move to `ProtectedRooms` - `logMessage` and `replaceRoomIdsWithPills` moved to `ManagementRoomOutput`. - `resyncJoinedRooms` has been made a little more clear, though I am concerned about how often it does run because it does seem expensive. * ProtectedRooms is not supposed to track joined rooms. The reason is because it is supposed to represent a specific set of rooms to protect, not do horrible logic for working out what rooms mjolnir is supposed to protect.
35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { strict as assert } from "assert";
|
|
import { LogLevel } from "matrix-bot-sdk";
|
|
import ManagementRoomOutput from "../../src/ManagementRoomOutput";
|
|
|
|
describe("Test: utils", function() {
|
|
it("replaceRoomIdsWithPills correctly turns a room ID in to a pill", async function() {
|
|
const managementRoomAlias = this.config.managementRoom;
|
|
const managementRoomOutput: ManagementRoomOutput = this.mjolnir.managementRoomOutput;
|
|
await this.mjolnir.client.sendStateEvent(
|
|
this.mjolnir.managementRoomId,
|
|
"m.room.canonical_alias",
|
|
"",
|
|
{ alias: managementRoomAlias }
|
|
);
|
|
|
|
const message: any = await new Promise(async resolve => {
|
|
this.mjolnir.client.on('room.message', (roomId, event) => {
|
|
if (roomId === this.mjolnir.managementRoomId) {
|
|
if (event.content?.body?.startsWith("it's")) {
|
|
resolve(event);
|
|
}
|
|
}
|
|
})
|
|
await managementRoomOutput.logMessage(LogLevel.INFO, 'replaceRoomIdsWithPills test',
|
|
`it's fun here in ${this.mjolnir.managementRoomId}`,
|
|
[this.mjolnir.managementRoomId, "!myfaketestid:example.com"]);
|
|
});
|
|
assert.equal(
|
|
message.content.formatted_body,
|
|
`it's fun here in <a href="https://matrix.to/#/${managementRoomAlias}">${managementRoomAlias}</a>`
|
|
);
|
|
});
|
|
});
|
|
|