From f8b9d84d9e55e009286c32dfb0c0d5d87f898b93 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Tue, 21 Jan 2025 14:20:31 +0000 Subject: [PATCH] verify, attendance: accept auditorium slugs --- src/Conference.ts | 28 +++++++++++++++++++ src/commands/AttendanceCommand.ts | 2 +- src/commands/VerifyCommand.ts | 45 +++++++++++++++---------------- 3 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/Conference.ts b/src/Conference.ts index 15cb042..804a1f1 100644 --- a/src/Conference.ts +++ b/src/Conference.ts @@ -804,6 +804,15 @@ export class Conference { return this.auditoriums[audId]; } + public getAuditoriumBySlug(audSlug: string): Auditorium | null { + for (let auditorium of Object.values(this.auditoriums)) { + if (auditorium.getSlug() === audSlug) { + return auditorium; + } + } + return null; + } + public getAuditoriumBackstage(audId: string): AuditoriumBackstage { return this.auditoriumBackstages[audId]; } @@ -816,6 +825,25 @@ export class Conference { return this.interestRooms[intId]; } + public getInterestById(audSlug: string): InterestRoom | null { + for (let interest of Object.values(this.interestRooms)) { + if (interest.getId() === audSlug) { + return interest; + } + } + return null; + } + + public getAuditoriumOrInterestByIdOrSlug(audOrInterestIdOrSlug: string): Auditorium | InterestRoom | null { + if (this.auditoriums[audOrInterestIdOrSlug]) { + return this.auditoriums[audOrInterestIdOrSlug]; + } + if (this.interestRooms[audOrInterestIdOrSlug]) { + return this.interestRooms[audOrInterestIdOrSlug]; + } + return this.getAuditoriumBySlug(audOrInterestIdOrSlug); + } + public async ensurePermissionsFor(people: ResolvedPersonIdentifier[], roomId: string): Promise { const mxids = people.filter(t => !!t.mxid).map(r => r.mxid!); diff --git a/src/commands/AttendanceCommand.ts b/src/commands/AttendanceCommand.ts index 9755c21..4a3bcaf 100644 --- a/src/commands/AttendanceCommand.ts +++ b/src/commands/AttendanceCommand.ts @@ -85,7 +85,7 @@ export class AttendanceCommand implements ICommand { if (withHtml) html += ""; }; for (const auditorium of this.conference.storedAuditoriums) { - const doAppend = !!targetAudId && (targetAudId === "all" || targetAudId === auditorium.getId()); + const doAppend = !!targetAudId && (targetAudId === "all" || targetAudId === auditorium.getId() || targetAudId === auditorium.getSlug()); const bs = this.conference.getAuditoriumBackstage(auditorium.getId()); const inviteTargets = await this.conference.getInviteTargetsForAuditorium(auditorium); const bsInviteTargets = await this.conference.getInviteTargetsForAuditorium(auditorium); diff --git a/src/commands/VerifyCommand.ts b/src/commands/VerifyCommand.ts index 49e1538..3c59677 100644 --- a/src/commands/VerifyCommand.ts +++ b/src/commands/VerifyCommand.ts @@ -29,31 +29,28 @@ export class VerifyCommand implements ICommand { constructor(private readonly client: MatrixClient, private readonly conference: Conference) {} public async run(roomId: string, event: any, args: string[]) { - let audId; + let targetIdOrSlug: string; let backstage = args[args.length - 1] === "backstage"; if (backstage) { const aud_slice = args.slice(0, -1) - audId = aud_slice.join(" ") + targetIdOrSlug = aud_slice.join(" ") } else { - audId = args.join(" "); + targetIdOrSlug = args.join(" "); } - let aud: PhysicalRoom = this.conference.getAuditorium(audId); - if (backstage) { - aud = this.conference.getAuditoriumBackstage(audId); + let room: PhysicalRoom | null = this.conference.getAuditoriumOrInterestByIdOrSlug(targetIdOrSlug); + if (backstage && room !== null) { + room = this.conference.getAuditoriumBackstage(room.getId()); } - if (!aud) { - aud = this.conference.getInterestRoom(audId); - if (!aud) { - return await this.client.replyNotice(roomId, event, `Unknown auditorium/interest room: ${audId}`); - } + if (!room) { + return await this.client.replyNotice(roomId, event, `Unknown auditorium/interest room: ${targetIdOrSlug}`); } await this.client.replyNotice(roomId, event, "Calculating list of people..."); - let html = `

${aud.getName()} (${aud.getId()})

`; + let html = `

${room.getName()} (${room.getId()})

`; const appendPeople = (invite: IPerson[], mods: IPerson[]) => { for (const target of invite) { @@ -66,30 +63,30 @@ export class VerifyCommand implements ICommand { let audBackstageToInvite: IPerson[]; let audToMod: IPerson[]; - if (aud instanceof Auditorium) { - audToInvite = await this.conference.getInviteTargetsForAuditorium(aud); - audBackstageToInvite = await this.conference.getInviteTargetsForAuditorium(aud); - audToMod = await this.conference.getModeratorsForAuditorium(aud); - } else if (aud instanceof InterestRoom) { - audToInvite = await this.conference.getInviteTargetsForInterest(aud); + if (room instanceof Auditorium) { + audToInvite = await this.conference.getInviteTargetsForAuditorium(room); + audBackstageToInvite = await this.conference.getInviteTargetsForAuditorium(room); + audToMod = await this.conference.getModeratorsForAuditorium(room); + } else if (room instanceof InterestRoom) { + audToInvite = await this.conference.getInviteTargetsForInterest(room); audBackstageToInvite = []; - audToMod = await this.conference.getModeratorsForInterest(aud); + audToMod = await this.conference.getModeratorsForInterest(room); } else { - return await this.client.replyNotice(roomId, event, `Unknown room kind: ${aud}`); + return await this.client.replyNotice(roomId, event, `Unknown room kind: ${room}`); } - const publicAud = this.conference.getAuditorium(audId); - if (publicAud || !(aud instanceof Auditorium)) { + const publicAud = this.conference.getAuditorium(targetIdOrSlug); + if (publicAud || !(room instanceof Auditorium)) { html += "Public-facing room:Backstage room:"; - const talks = await asyncFilter(this.conference.storedTalks, async t => t.getAuditoriumId() === aud.getId()); + const talks = await asyncFilter(this.conference.storedTalks, async t => t.getAuditoriumId() === room!.getId()); for (const talk of talks) { const talkToInvite = await this.conference.getInviteTargetsForTalk(talk); const talkToMod = await this.conference.getModeratorsForTalk(talk);