Skip to content

Commit

Permalink
verify, attendance: accept auditorium slugs
Browse files Browse the repository at this point in the history
  • Loading branch information
reivilibre committed Jan 21, 2025
1 parent b8fa147 commit f8b9d84
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 25 deletions.
28 changes: 28 additions & 0 deletions src/Conference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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<void> {
const mxids = people.filter(t => !!t.mxid).map(r => r.mxid!);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/AttendanceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class AttendanceCommand implements ICommand {
if (withHtml) html += "</li>";
};
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);
Expand Down
45 changes: 21 additions & 24 deletions src/commands/VerifyCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `<h1>${aud.getName()} (${aud.getId()})</h1>`;
let html = `<h1>${room.getName()} (${room.getId()})</h1>`;

const appendPeople = (invite: IPerson[], mods: IPerson[]) => {
for (const target of invite) {
Expand All @@ -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 += "<b>Public-facing room:</b><ul>";
appendPeople(audToInvite, audToMod);
}

if (aud instanceof Auditorium) {
if (room instanceof Auditorium) {
html += "</ul><b>Backstage room:</b><ul>";
appendPeople(audBackstageToInvite, audToMod);
html += "</ul>";

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);
Expand Down

0 comments on commit f8b9d84

Please sign in to comment.