Skip to content

Commit c887f65

Browse files
committed
Count number of sent invites
1 parent 5f2e61e commit c887f65

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/commands/InviteCommand.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class InviteCommand implements ICommand {
3030

3131
constructor(private readonly client: ConferenceMatrixClient, private readonly conference: Conference, private readonly config: IConfig) {}
3232

33-
private async createInvites(people: IPerson[], alias: string) {
33+
private async createInvites(people: IPerson[], alias: string): Promise<number> {
3434
const resolved = await resolveIdentifiers(this.client, people);
3535

3636
let targetRoomId;
@@ -40,7 +40,7 @@ export class InviteCommand implements ICommand {
4040
catch (error) {
4141
throw Error(`Error resolving room id for ${alias}`, {cause: error})
4242
}
43-
await this.ensureInvited(targetRoomId, resolved);
43+
return await this.ensureInvited(targetRoomId, resolved);
4444
}
4545

4646
public async run(managementRoomId: string, event: any, args: string[]) {
@@ -51,6 +51,8 @@ export class InviteCommand implements ICommand {
5151
// in it. We don't remove anyone and don't care about extras - we just want to make sure
5252
// that a subset of people are joined.
5353

54+
let invitesSent = 0;
55+
5456
if (args[0] && args[0] === "speakers-support") {
5557
let people: IPerson[] = [];
5658
for (const aud of this.conference.storedAuditoriumBackstages) {
@@ -62,7 +64,7 @@ export class InviteCommand implements ICommand {
6264
newPeople.push(p);
6365
}
6466
});
65-
await this.createInvites(newPeople, this.config.conference.supportRooms.speakers);
67+
invitesSent += await this.createInvites(newPeople, this.config.conference.supportRooms.speakers);
6668
} else if (args[0] && args[0] === "coordinators-support") {
6769
let people: IPerson[] = [];
6870
for (const aud of this.conference.storedAuditoriums) {
@@ -83,24 +85,27 @@ export class InviteCommand implements ICommand {
8385
newPeople.push(p);
8486
}
8587
});
86-
await this.createInvites(newPeople, this.config.conference.supportRooms.coordinators);
88+
invitesSent += await this.createInvites(newPeople, this.config.conference.supportRooms.coordinators);
8789
} else if (args[0] && args[0] === "si-support") {
8890
const people: IPerson[] = [];
8991
for (const sir of this.conference.storedInterestRooms) {
9092
people.push(...await this.conference.getInviteTargetsForInterest(sir));
9193
}
92-
await this.createInvites(people, this.config.conference.supportRooms.specialInterest);
94+
invitesSent += await this.createInvites(people, this.config.conference.supportRooms.specialInterest);
9395
} 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);
9599
}
96100

97-
await this.client.sendNotice(managementRoomId, "Invites sent!");
101+
await this.client.sendNotice(managementRoomId, `${invitesSent} invites sent!`);
98102
}
99103

100-
public async ensureInvited(roomId: string, people: ResolvedPersonIdentifier[]) {
104+
public async ensureInvited(roomId: string, people: ResolvedPersonIdentifier[]): Promise<number> {
101105
// We don't want to invite anyone we have already invited or that has joined though, so
102106
// avoid those people. We do this by querying the room state and filtering.
103-
let state;
107+
let invitesSent = 0;
108+
let state: any[];
104109
try {
105110
state = await this.client.getRoomState(roomId);
106111
}
@@ -115,10 +120,13 @@ export class InviteCommand implements ICommand {
115120
if (emailInvitePersonIds.includes(target.person.id)) continue;
116121
try {
117122
await invitePersonToRoom(this.client, target, roomId, this.config);
123+
++invitesSent;
118124
} catch (e) {
119125
LogService.error("InviteCommand", e);
120126
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);
121127
}
122128
}
129+
130+
return invitesSent;
123131
}
124132
}

0 commit comments

Comments
 (0)