From ae86e173f5a05e89e5016bf22d0a114c7880ffc6 Mon Sep 17 00:00:00 2001 From: Gnuxie <50846879+Gnuxie@users.noreply.github.com> Date: Tue, 16 Apr 2024 12:24:17 +0100 Subject: [PATCH] Update for MPS 0.17.1. (#347) * Update for MPS 0.17.1. Part of https://github.com/the-draupnir-project/Draupnir/issues/333 And https://github.com/the-draupnir-project/Draupnir/issues/345 Fixes https://github.com/the-draupnir-project/Draupnir/issues/337 * Add loggableConfigTracker to Draupnir. Part of https://github.com/the-draupnir-project/Draupnir/issues/217. I don't think this is right yet. --- package.json | 4 ++-- src/Draupnir.ts | 9 ++++++--- src/draupnirfactory/DraupnirFactory.ts | 9 ++++++--- .../DraupnirProtectedRoomsSet.ts | 10 +++++++--- yarn.lock | 18 +++++++++--------- 5 files changed, 30 insertions(+), 20 deletions(-) diff --git a/package.json b/package.json index 55b841b9..706fa4ad 100644 --- a/package.json +++ b/package.json @@ -63,8 +63,8 @@ "js-yaml": "^4.1.0", "jsdom": "^24.0.0", "matrix-appservice-bridge": "^9.0.1", - "matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@0.16.0", - "matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@0.16.1", + "matrix-protection-suite": "npm:@gnuxie/matrix-protection-suite@0.17.1", + "matrix-protection-suite-for-matrix-bot-sdk": "npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@0.17.1", "parse-duration": "^1.0.2", "pg": "^8.8.0", "shell-quote": "^1.7.3", diff --git a/src/Draupnir.ts b/src/Draupnir.ts index d8c92cc3..8855b1d3 100644 --- a/src/Draupnir.ts +++ b/src/Draupnir.ts @@ -25,7 +25,7 @@ limitations under the License. * are NOT distributed, contributed, committed, or licensed under the Apache License. */ -import { ActionResult, Client, ClientPlatform, ClientRooms, EventReport, Logger, MatrixRoomID, MatrixRoomReference, Membership, MembershipEvent, Ok, PolicyRoomManager, ProtectedRoomsSet, RoomEvent, RoomMembershipManager, RoomMessage, RoomStateManager, StringRoomID, StringUserID, Task, TextMessageContent, Value, isError, isStringRoomAlias, isStringRoomID, serverName, userLocalpart } from "matrix-protection-suite"; +import { ActionResult, Client, ClientPlatform, ClientRooms, EventReport, LoggableConfigTracker, Logger, MatrixRoomID, MatrixRoomReference, Membership, MembershipEvent, Ok, PolicyRoomManager, ProtectedRoomsSet, RoomEvent, RoomMembershipManager, RoomMessage, RoomStateManager, StringRoomID, StringUserID, Task, TextMessageContent, Value, isError, isStringRoomAlias, isStringRoomID, serverName, userLocalpart } from "matrix-protection-suite"; import { UnlistedUserRedactionQueue } from "./queues/UnlistedUserRedactionQueue"; import { findCommandTable } from "./commands/interface-manager/InterfaceCommand"; import { ThrottlingQueue } from "./queues/ThrottlingQueue"; @@ -94,7 +94,8 @@ export class Draupnir implements Client { public readonly roomStateManager: RoomStateManager, public readonly policyRoomManager: PolicyRoomManager, public readonly roomMembershipManager: RoomMembershipManager, - public readonly synapseAdminClient?: SynapseAdminClient + public readonly loggableConfigTracker: LoggableConfigTracker, + public readonly synapseAdminClient?: SynapseAdminClient, ) { this.managementRoomID = this.managementRoom.toRoomIDOrAlias(); this.managementRoomOutput = new ManagementRoomOutput( @@ -138,7 +139,8 @@ export class Draupnir implements Client { roomStateManager: RoomStateManager, policyRoomManager: PolicyRoomManager, roomMembershipManager: RoomMembershipManager, - config: IConfig + config: IConfig, + loggableConfigTracker: LoggableConfigTracker ): Promise> { const draupnir = new Draupnir( client, @@ -151,6 +153,7 @@ export class Draupnir implements Client { roomStateManager, policyRoomManager, roomMembershipManager, + loggableConfigTracker, new SynapseAdminClient( client, clientUserID diff --git a/src/draupnirfactory/DraupnirFactory.ts b/src/draupnirfactory/DraupnirFactory.ts index 94d4763b..541d0467 100644 --- a/src/draupnirfactory/DraupnirFactory.ts +++ b/src/draupnirfactory/DraupnirFactory.ts @@ -3,7 +3,7 @@ * All rights reserved. */ -import { ActionResult, ClientsInRoomMap, MatrixRoomID, StringUserID, isError } from "matrix-protection-suite"; +import { ActionResult, ClientsInRoomMap, MatrixRoomID, StandardLoggableConfigTracker, StringUserID, isError } from "matrix-protection-suite"; import { Draupnir } from "../Draupnir"; import { ClientCapabilityFactory, ClientForUserID, RoomStateManagerFactory, joinedRoomsSafe } from "matrix-protection-suite-for-matrix-bot-sdk"; import { IConfig } from "../config"; @@ -32,6 +32,7 @@ export class DraupnirFactory { return clientRooms; } const clientPlatform = this.clientCapabilityFactory.makeClientPlatform(clientUserID, client); + const configLogTracker = new StandardLoggableConfigTracker(); const protectedRoomsSet = await makeProtectedRoomsSet( managementRoom, roomStateManager, @@ -40,7 +41,8 @@ export class DraupnirFactory { client, clientPlatform, clientUserID, - config + config, + configLogTracker ); if (isError(protectedRoomsSet)) { return protectedRoomsSet; @@ -55,7 +57,8 @@ export class DraupnirFactory { roomStateManager, policyRoomManager, roomMembershipManager, - config + config, + configLogTracker ); } } diff --git a/src/draupnirfactory/DraupnirProtectedRoomsSet.ts b/src/draupnirfactory/DraupnirProtectedRoomsSet.ts index 2a6e6139..59909316 100644 --- a/src/draupnirfactory/DraupnirProtectedRoomsSet.ts +++ b/src/draupnirfactory/DraupnirProtectedRoomsSet.ts @@ -25,7 +25,7 @@ limitations under the License. * are NOT distributed, contributed, committed, or licensed under the Apache License. */ -import { ActionResult, ClientPlatform, Logger, MJOLNIR_PROTECTED_ROOMS_EVENT_TYPE, MJOLNIR_WATCHED_POLICY_ROOMS_EVENT_TYPE, MatrixRoomID, MissingProtectionCB, MjolnirEnabledProtectionsEvent, MjolnirEnabledProtectionsEventType, MjolnirPolicyRoomsConfig, MjolnirProtectedRoomsConfig, MjolnirProtectedRoomsEvent, MjolnirProtectionSettingsEventType, MjolnirProtectionsConfig, MjolnirWatchedPolicyRoomsEvent, Ok, PolicyListConfig, PolicyRoomManager, ProtectedRoomsConfig, ProtectedRoomsSet, ProtectionsManager, RoomJoiner, RoomMembershipManager, RoomStateManager, SetMembership, SetRoomState, StandardProtectedRoomsSet, StandardProtectionsManager, StandardSetMembership, StandardSetRoomState, StringUserID, isError } from "matrix-protection-suite"; +import { ActionResult, ClientPlatform, LoggableConfigTracker, Logger, MJOLNIR_PROTECTED_ROOMS_EVENT_TYPE, MJOLNIR_WATCHED_POLICY_ROOMS_EVENT_TYPE, MatrixRoomID, MissingProtectionCB, MjolnirEnabledProtectionsEvent, MjolnirEnabledProtectionsEventType, MjolnirPolicyRoomsConfig, MjolnirProtectedRoomsConfig, MjolnirProtectedRoomsEvent, MjolnirProtectionSettingsEventType, MjolnirProtectionsConfig, MjolnirWatchedPolicyRoomsEvent, Ok, PolicyListConfig, PolicyRoomManager, ProtectedRoomsConfig, ProtectedRoomsSet, ProtectionsManager, RoomJoiner, RoomMembershipManager, RoomStateManager, SetMembership, SetRoomState, StandardProtectedRoomsSet, StandardProtectionsManager, StandardSetMembership, StandardSetRoomState, StringUserID, isError } from "matrix-protection-suite"; import { BotSDKMatrixAccountData, BotSDKMatrixStateData, MatrixSendClient } from "matrix-protection-suite-for-matrix-bot-sdk"; import { DefaultEnabledProtectionsMigration } from "../protections/DefaultEnabledProtectionsMigration"; import '../protections/DraupnirProtectionsIndex'; @@ -98,7 +98,8 @@ async function makeProtectionsManager( client: MatrixSendClient, roomStateManager: RoomStateManager, managementRoom: MatrixRoomID, - config: IConfig + config: IConfig, + loggableConfigTracker: LoggableConfigTracker ): Promise> { const result = await roomStateManager.getRoomStateRevisionIssuer( managementRoom @@ -112,6 +113,7 @@ async function makeProtectionsManager( MjolnirEnabledProtectionsEvent, client ), + loggableConfigTracker, { migrationHandler: DefaultEnabledProtectionsMigration, missingProtectionCB: makeMissingProtectionCB() @@ -146,6 +148,7 @@ export async function makeProtectedRoomsSet( clientPlatform: ClientPlatform, userID: StringUserID, config: IConfig, + loggableConfigTracker: LoggableConfigTracker, ): Promise> { const protectedRoomsConfig = await makeProtectedRoomsConfig(client, clientPlatform.toRoomJoiner()) if (isError(protectedRoomsConfig)) { @@ -173,7 +176,8 @@ export async function makeProtectedRoomsSet( client, roomStateManager, managementRoom, - config + config, + loggableConfigTracker ); if (isError(protectionsConfig)) { return protectionsConfig; diff --git a/yarn.lock b/yarn.lock index de58ecab..dba5e1fb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2505,15 +2505,15 @@ matrix-appservice@^2.0.0: request-promise "^4.2.6" sanitize-html "^2.8.0" -"matrix-protection-suite-for-matrix-bot-sdk@npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@0.16.1": - version "0.16.1" - resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite-for-matrix-bot-sdk/-/matrix-protection-suite-for-matrix-bot-sdk-0.16.1.tgz#322d6cb88cb158140f432e1f853a69e8697cd6a5" - integrity sha512-fipZknx+QNuwNHV+er6LWdnUJ8/6NhuIpqP9O8zdMVC8Wn+/vNcAzTKCO3k9ulDNYtTgA8M+dyOlg0nOJVCJAQ== - -"matrix-protection-suite@npm:@gnuxie/matrix-protection-suite@0.16.0": - version "0.16.0" - resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite/-/matrix-protection-suite-0.16.0.tgz#380367f76721373e13cc04399ddffa0b9b1ee9c0" - integrity sha512-XNAaECsv3CUYZN2mBiwVrG+qOs+KP0NDIw353/KtZFOAoAKwCFltXpPoQe/TT+Lc0eSVxfKtW6+rofWBccjfVQ== +"matrix-protection-suite-for-matrix-bot-sdk@npm:@gnuxie/matrix-protection-suite-for-matrix-bot-sdk@0.17.1": + version "0.17.1" + resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite-for-matrix-bot-sdk/-/matrix-protection-suite-for-matrix-bot-sdk-0.17.1.tgz#925363e0282879156c9f9b7673a8e6acd78e1a71" + integrity sha512-8vIu51ZLlVDUqRgz6K7bQMSjp/DEY+q1AO2mqvO/cSnHly/XKaflszwxN9zySAj6JjFXgPt+z1WkqV5omWE9NA== + +"matrix-protection-suite@npm:@gnuxie/matrix-protection-suite@0.17.1": + version "0.17.1" + resolved "https://registry.yarnpkg.com/@gnuxie/matrix-protection-suite/-/matrix-protection-suite-0.17.1.tgz#7c4330a029461652d61d89ba5461c99324cfc3a1" + integrity sha512-3p9OqHf1JKymD1igceA5qy008Bqf9hSXC6mhPlLPqL7JGLFyE5FHa3eJcJJorZAfq54TH+KVmgpL0Es+E/wxfQ== dependencies: await-lock "^2.2.2" crypto-js "^4.1.1"