Skip to content

Commit 340b81a

Browse files
authored
For support room invites, fix multiple-role people not being invited (#231)
* HACK Coordinator role trumps Speaker role * Apply invite target filtering at the source, before role trumps This is because the speakers room should not have devroom managers
1 parent b91e633 commit 340b81a

File tree

6 files changed

+30
-22
lines changed

6 files changed

+30
-22
lines changed

src/Conference.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -747,24 +747,33 @@ export class Conference {
747747
return [];
748748
}
749749

750-
public async getInviteTargetsForAuditorium(auditorium: Auditorium, backstage = false): Promise<IPerson[]> {
750+
public async getInviteTargetsForAuditorium(auditorium: Auditorium, roles = [Role.Coordinator, Role.Host, Role.Speaker]): Promise<IPerson[]> {
751751
const people = await this.getPeopleForAuditorium(auditorium);
752-
const roles = [Role.Coordinator, Role.Host, Role.Speaker];
753-
let includesPerson = (person, array) => {
754-
for (const element of array) {
755-
if (element.name === person.name) {
756-
return true
757-
}
758-
}
759-
return false
752+
753+
// HACK dedupe people by name.
754+
const namesToPersons: Map<string, IPerson> = new Map();
755+
756+
let shouldWritePerson = (person: IPerson) => {
757+
// ignore unknown roles
758+
if (! roles.includes(person.role)) return false;
759+
760+
if (! namesToPersons.has(person.name)) return true;
761+
762+
// (TODO HACK we should figure out a nicer way of doing this, like directly tracking multiple roles for people)
763+
// overwrite the previous person entry if this person is a coordinator
764+
// (coordinator role is more important than speaker)
765+
if (person.role == Role.Coordinator) return true;
766+
767+
return false;
760768
};
761-
let uniquePeople: IPerson[] = []
769+
762770
for (const person of people) {
763-
if (!includesPerson(person, uniquePeople)) {
764-
uniquePeople.push(person)
771+
if (shouldWritePerson(person)) {
772+
namesToPersons.set(person.name, person);
765773
}
766774
}
767-
return uniquePeople.filter(p => roles.includes(p.role));
775+
776+
return Array.from(namesToPersons.values());
768777
}
769778

770779
public async getInviteTargetsForTalk(talk: Talk): Promise<IPerson[]> {

src/commands/AttendanceCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class AttendanceCommand implements ICommand {
8888
const doAppend = !!targetAudId && (targetAudId === "all" || targetAudId === await auditorium.getId());
8989
const bs = this.conference.getAuditoriumBackstage(await auditorium.getId());
9090
const inviteTargets = await this.conference.getInviteTargetsForAuditorium(auditorium);
91-
const bsInviteTargets = await this.conference.getInviteTargetsForAuditorium(auditorium, true);
91+
const bsInviteTargets = await this.conference.getInviteTargetsForAuditorium(auditorium);
9292
try {
9393
await append(inviteTargets, bsInviteTargets, await auditorium.getId(), auditorium.roomId, bs.roomId, doAppend);
9494
}

src/commands/DevCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class DevCommand implements ICommand {
2727
public async run(roomId: string, event: any, args: string[]) {
2828
let people: IPerson[] = [];
2929
for (const aud of this.conference.storedAuditoriums) {
30-
const inviteTargets = await this.conference.getInviteTargetsForAuditorium(aud, true);
30+
const inviteTargets = await this.conference.getInviteTargetsForAuditorium(aud);
3131
people.push(...inviteTargets.filter(i => i.role === Role.Coordinator));
3232
}
3333
const newPeople: IPerson[] = [];

src/commands/InviteCommand.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ export class InviteCommand implements ICommand {
5454
if (args[0] && args[0] === "speakers-support") {
5555
let people: IPerson[] = [];
5656
for (const aud of this.conference.storedAuditoriumBackstages) {
57-
people.push(...await this.conference.getInviteTargetsForAuditorium(aud, true));
57+
people.push(...await this.conference.getInviteTargetsForAuditorium(aud, [Role.Speaker]));
5858
}
59-
people = people.filter(p => p.role === Role.Speaker);
6059
const newPeople: IPerson[] = [];
6160
people.forEach(p => {
6261
if (!newPeople.some(n => n.id === p.id)) {
@@ -75,8 +74,8 @@ export class InviteCommand implements ICommand {
7574
// continue;
7675
// }
7776

78-
const inviteTargets = await this.conference.getInviteTargetsForAuditorium(aud, true);
79-
people.push(...inviteTargets.filter(i => i.role === Role.Coordinator));
77+
const inviteTargets = await this.conference.getInviteTargetsForAuditorium(aud, [Role.Coordinator]);
78+
people.push(...inviteTargets);
8079
}
8180
const newPeople: IPerson[] = [];
8281
people.forEach(p => {

src/commands/VerifyCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class VerifyCommand implements ICommand {
6868

6969
if (aud instanceof Auditorium) {
7070
audToInvite = await this.conference.getInviteTargetsForAuditorium(aud);
71-
audBackstageToInvite = await this.conference.getInviteTargetsForAuditorium(aud, true);
71+
audBackstageToInvite = await this.conference.getInviteTargetsForAuditorium(aud);
7272
audToMod = await this.conference.getModeratorsForAuditorium(aud);
7373
} else if (aud instanceof InterestRoom) {
7474
audToInvite = await this.conference.getInviteTargetsForInterest(aud);

src/commands/actions/people.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function doAuditoriumResolveAction(
4040
// We know that everyone should be in the backstage room, so resolve that list of people
4141
// to make the identity server lookup efficient.
4242
const backstagePeople = isInvite
43-
? await conference.getInviteTargetsForAuditorium(aud, true)
43+
? await conference.getInviteTargetsForAuditorium(aud)
4444
: await conference.getModeratorsForAuditorium(aud);
4545
LogService.info("backstagePeople", `${backstagePeople}`);
4646
const resolvedBackstagePeople = await resolveIdentifiers(client, backstagePeople);
@@ -50,7 +50,7 @@ export async function doAuditoriumResolveAction(
5050

5151
const allPossiblePeople = isInvite
5252
? resolvedBackstagePeople
53-
: await resolveIdentifiers(client, await conference.getInviteTargetsForAuditorium(aud, true));
53+
: await resolveIdentifiers(client, await conference.getInviteTargetsForAuditorium(aud));
5454

5555
await action(client, backstage.roomId, resolvedBackstagePeople);
5656

0 commit comments

Comments
 (0)