@@ -15,6 +15,7 @@ import {
1515 Protection ,
1616 ProtectionDescription ,
1717 RoomCreator ,
18+ RoomInviter ,
1819 RoomMembershipManager ,
1920 RoomStateEventSender ,
2021} from "matrix-protection-suite" ;
@@ -33,6 +34,7 @@ export class NotificationRoomCreator<
3334 private readonly protectedRoomsManager : ProtectedRoomsManager ,
3435 private readonly settingChangeCB : SettingChangeAndProtectionEnableCB < TProtectionDescription > ,
3536 private readonly roomCreateCapability : RoomCreator ,
37+ private readonly roomInviter : RoomInviter ,
3638 private readonly roomStateEventCapability : RoomStateEventSender ,
3739 private readonly roomName : string ,
3840 private readonly draupnirUserID : StringUserID ,
@@ -56,6 +58,7 @@ export class NotificationRoomCreator<
5658 const revision = membershipRevisionIssuer . ok . currentRevision ;
5759 return Ok (
5860 [ ...revision . members ( ) ]
61+ . filter ( ( member ) => member . membership === "join" )
5962 . map ( ( member ) => member . userID )
6063 . filter ( ( userID ) => userID !== draupnirUserID )
6164 ) ;
@@ -106,6 +109,7 @@ export class NotificationRoomCreator<
106109 return result ;
107110 } ,
108111 draupnir . clientPlatform . toRoomCreator ( ) ,
112+ draupnir . clientPlatform . toRoomInviter ( ) ,
109113 draupnir . clientPlatform . toRoomStateEventSender ( ) ,
110114 notificationRoomName ,
111115 draupnir . clientUserID ,
@@ -123,7 +127,6 @@ export class NotificationRoomCreator<
123127 const newRoom = await this . roomCreateCapability . createRoom ( {
124128 preset : "private_chat" ,
125129 name : roomTitle ,
126- invite : this . draupnirModerators ,
127130 } ) ;
128131 if ( isError ( newRoom ) ) {
129132 this . log . error (
@@ -174,6 +177,21 @@ export class NotificationRoomCreator<
174177 ) ;
175178 return protectionEnableResult ;
176179 }
180+ // We invite seperate to the /createRoom call because otherwise the entire /createRoom
181+ // call will fail if just one user couldn't be invited. Which is really bad.
182+ // This happens when servers are no longer reachable.
183+ for ( const invitee of this . draupnirModerators ) {
184+ const inviteResult = await this . roomInviter . inviteUser (
185+ newRoom . ok ,
186+ invitee
187+ ) ;
188+ if ( isError ( inviteResult ) ) {
189+ this . log . error (
190+ `Failed to invite moderator ${ invitee } to notification room for ${ this . roomName } ` ,
191+ inviteResult . error
192+ ) ;
193+ }
194+ }
177195 return protectionEnableResult ;
178196 }
179197}
0 commit comments