1111import {
1212 AbstractProtection ,
1313 ActionResult ,
14+ EDStatic ,
1415 Logger ,
1516 Ok ,
1617 PolicyListRevision ,
@@ -20,7 +21,7 @@ import {
2021 PolicyRuleMatchType ,
2122 ProtectedRoomsSet ,
2223 ProtectionDescription ,
23- UnknownConfig ,
24+ StringRoomIDSchema ,
2425 describeProtection ,
2526 isError ,
2627} from "matrix-protection-suite" ;
@@ -40,15 +41,31 @@ import {
4041 DocumentNode ,
4142} from "@the-draupnir-project/interface-manager" ;
4243import { renderRuleHashes , renderRuleClearText } from "../commands/Rules" ;
44+ import { NotificationRoomCreator } from "./NotificationRoom/NotificationRoom" ;
45+ import { Type } from "@sinclair/typebox" ;
46+ import { Result } from "@gnuxie/typescript-result" ;
4347
4448const log = new Logger ( "PolicyChangeNotification" ) ;
4549
50+ const PolicyChangeNotificationSettings = Type . Object ( {
51+ notificationRoomID : Type . Optional (
52+ Type . Union ( [ StringRoomIDSchema , Type . Undefined ( ) ] , {
53+ default : undefined ,
54+ description : "The room where notifications should be sent." ,
55+ } )
56+ ) ,
57+ } ) ;
58+
59+ export type PolicyChangeNotificationSettings = EDStatic <
60+ typeof PolicyChangeNotificationSettings
61+ > ;
62+
4663export type PolicyChangeNotificationCapabilitites = Record < never , never > ;
4764
4865export type PolicyChangeNotificationProtectionDescription =
4966 ProtectionDescription <
5067 Draupnir ,
51- UnknownConfig ,
68+ typeof PolicyChangeNotificationSettings ,
5269 PolicyChangeNotificationCapabilitites
5370 > ;
5471
@@ -62,7 +79,8 @@ export class PolicyChangeNotification
6279 description : PolicyChangeNotificationProtectionDescription ,
6380 capabilities : PolicyChangeNotificationCapabilitites ,
6481 protectedRoomsSet : ProtectedRoomsSet ,
65- private readonly draupnir : Draupnir
82+ private readonly draupnir : Draupnir ,
83+ public readonly notificationRoomID : StringRoomID
6684 ) {
6785 super ( description , capabilities , protectedRoomsSet , { } ) ;
6886 }
@@ -92,7 +110,7 @@ export class PolicyChangeNotification
92110 }
93111 const sendResult = await sendMatrixEventsFromDeadDocument (
94112 this . draupnir . clientPlatform . toRoomMessageSender ( ) ,
95- this . draupnir . managementRoomID ,
113+ this . notificationRoomID ,
96114 < root > { renderGroupedChanges ( groupedChanges . ok ) } </ root > ,
97115 { }
98116 ) ;
@@ -159,24 +177,40 @@ function renderGroupedChanges(groupedChanges: GroupedChange[]): DocumentNode {
159177 return < fragment > { groupedChanges . map ( renderListChanges ) } </ fragment > ;
160178}
161179
162- describeProtection < PolicyChangeNotificationCapabilitites , Draupnir > ( {
180+ describeProtection <
181+ PolicyChangeNotificationCapabilitites ,
182+ Draupnir ,
183+ typeof PolicyChangeNotificationSettings
184+ > ( {
163185 name : PolicyChangeNotification . name ,
164186 description : "Provides notification of policy changes from watched lists." ,
165187 capabilityInterfaces : { } ,
166188 defaultCapabilities : { } ,
189+ configSchema : PolicyChangeNotificationSettings ,
167190 async factory (
168191 description ,
169192 protectedRoomsSet ,
170193 draupnir ,
171194 capabilities ,
172- _settings
195+ settings
173196 ) {
197+ if ( settings . notificationRoomID === undefined ) {
198+ return ( await NotificationRoomCreator . createNotificationRoomFromDraupnir (
199+ draupnir ,
200+ description as unknown as ProtectionDescription ,
201+ settings ,
202+ "notificationRoomID" ,
203+ "Policy Change Notifications" ,
204+ log
205+ ) ) as Result < PolicyChangeNotification > ;
206+ }
174207 return Ok (
175208 new PolicyChangeNotification (
176209 description ,
177210 capabilities ,
178211 protectedRoomsSet ,
179- draupnir
212+ draupnir ,
213+ settings . notificationRoomID
180214 )
181215 ) ;
182216 } ,
0 commit comments