@@ -30,7 +30,7 @@ export class InviteCommand implements ICommand {
30
30
31
31
constructor ( private readonly client : ConferenceMatrixClient , private readonly conference : Conference , private readonly config : IConfig ) { }
32
32
33
- private async createInvites ( people : IPerson [ ] , alias : string ) {
33
+ private async createInvites ( people : IPerson [ ] , alias : string ) : Promise < number > {
34
34
const resolved = await resolveIdentifiers ( this . client , people ) ;
35
35
36
36
let targetRoomId ;
@@ -40,7 +40,7 @@ export class InviteCommand implements ICommand {
40
40
catch ( error ) {
41
41
throw Error ( `Error resolving room id for ${ alias } ` , { cause : error } )
42
42
}
43
- await this . ensureInvited ( targetRoomId , resolved ) ;
43
+ return await this . ensureInvited ( targetRoomId , resolved ) ;
44
44
}
45
45
46
46
public async run ( managementRoomId : string , event : any , args : string [ ] ) {
@@ -51,6 +51,8 @@ export class InviteCommand implements ICommand {
51
51
// in it. We don't remove anyone and don't care about extras - we just want to make sure
52
52
// that a subset of people are joined.
53
53
54
+ let invitesSent = 0 ;
55
+
54
56
if ( args [ 0 ] && args [ 0 ] === "speakers-support" ) {
55
57
let people : IPerson [ ] = [ ] ;
56
58
for ( const aud of this . conference . storedAuditoriumBackstages ) {
@@ -62,7 +64,7 @@ export class InviteCommand implements ICommand {
62
64
newPeople . push ( p ) ;
63
65
}
64
66
} ) ;
65
- await this . createInvites ( newPeople , this . config . conference . supportRooms . speakers ) ;
67
+ invitesSent += await this . createInvites ( newPeople , this . config . conference . supportRooms . speakers ) ;
66
68
} else if ( args [ 0 ] && args [ 0 ] === "coordinators-support" ) {
67
69
let people : IPerson [ ] = [ ] ;
68
70
for ( const aud of this . conference . storedAuditoriums ) {
@@ -83,24 +85,27 @@ export class InviteCommand implements ICommand {
83
85
newPeople . push ( p ) ;
84
86
}
85
87
} ) ;
86
- await this . createInvites ( newPeople , this . config . conference . supportRooms . coordinators ) ;
88
+ invitesSent += await this . createInvites ( newPeople , this . config . conference . supportRooms . coordinators ) ;
87
89
} else if ( args [ 0 ] && args [ 0 ] === "si-support" ) {
88
90
const people : IPerson [ ] = [ ] ;
89
91
for ( const sir of this . conference . storedInterestRooms ) {
90
92
people . push ( ...await this . conference . getInviteTargetsForInterest ( sir ) ) ;
91
93
}
92
- await this . createInvites ( people , this . config . conference . supportRooms . specialInterest ) ;
94
+ invitesSent += await this . createInvites ( people , this . config . conference . supportRooms . specialInterest ) ;
93
95
} else {
94
- await runRoleCommand ( ( _client , room , people ) => this . ensureInvited ( room , people ) , this . conference , this . client , managementRoomId , event , args ) ;
96
+ await runRoleCommand ( async ( _client , room , people ) => {
97
+ invitesSent += await this . ensureInvited ( room , people ) ;
98
+ } , this . conference , this . client , managementRoomId , event , args ) ;
95
99
}
96
100
97
- await this . client . sendNotice ( managementRoomId , "Invites sent!" ) ;
101
+ await this . client . sendNotice ( managementRoomId , ` ${ invitesSent } invites sent!` ) ;
98
102
}
99
103
100
- public async ensureInvited ( roomId : string , people : ResolvedPersonIdentifier [ ] ) {
104
+ public async ensureInvited ( roomId : string , people : ResolvedPersonIdentifier [ ] ) : Promise < number > {
101
105
// We don't want to invite anyone we have already invited or that has joined though, so
102
106
// avoid those people. We do this by querying the room state and filtering.
103
- let state ;
107
+ let invitesSent = 0 ;
108
+ let state : any [ ] ;
104
109
try {
105
110
state = await this . client . getRoomState ( roomId ) ;
106
111
}
@@ -115,10 +120,13 @@ export class InviteCommand implements ICommand {
115
120
if ( emailInvitePersonIds . includes ( target . person . id ) ) continue ;
116
121
try {
117
122
await invitePersonToRoom ( this . client , target , roomId , this . config ) ;
123
+ ++ invitesSent ;
118
124
} catch ( e ) {
119
125
LogService . error ( "InviteCommand" , e ) ;
120
126
await logMessage ( LogLevel . ERROR , "InviteCommand" , `Error inviting ${ target . mxid } /${ target . emails } / ${ target . person . id } to ${ roomId } - ignoring: ${ e . message ?? e . statusMessage ?? '(see logs)' } ` , this . client ) ;
121
127
}
122
128
}
129
+
130
+ return invitesSent ;
123
131
}
124
132
}
0 commit comments