Skip to content

Commit 6fcc7a2

Browse files
Improvements to the 'room groups' on the inviteto/inviteme command (#175)
Co-authored-by: Will Hunt <[email protected]>
1 parent 90c8b32 commit 6fcc7a2

File tree

2 files changed

+39
-18
lines changed

2 files changed

+39
-18
lines changed

src/commands/InviteMeCommand.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,36 @@ export class InviteMeCommand implements ICommand {
4343

4444
for (const aud of conference.storedAuditoriums) {
4545
addToGroup("auditorium", aud.roomId);
46-
const audId = await aud.getId();
47-
addToGroup(audId + ":*", aud.roomId);
48-
addToGroup(audId + ":public", aud.roomId);
46+
const audSlug = await aud.getSlug();
47+
addToGroup(audSlug + ":*", aud.roomId);
48+
addToGroup(audSlug + ":public", aud.roomId);
4949
addToGroup("public", aud.roomId);
5050
addToGroup("*", aud.roomId);
5151

5252
// Auditoriums have a wrapping space, which should be auto-invited if needed.
5353
const space = await aud.getAssociatedSpace();
54-
addToGroup(audId + ":*", space.roomId);
55-
addToGroup(audId + ":public", space.roomId);
56-
addToGroup(audId + ":space", space.roomId);
54+
addToGroup(audSlug + ":*", space.roomId);
55+
addToGroup(audSlug + ":public", space.roomId);
56+
addToGroup(audSlug + ":space", space.roomId);
5757
addToGroup("public", space.roomId);
5858
addToGroup("*", space.roomId);
5959
}
6060

6161
for (const audBack of conference.storedAuditoriumBackstages) {
6262
addToGroup("auditorium_backstage", audBack.roomId);
63-
const audId = await audBack.getId();
64-
addToGroup(audId + ":*", audBack.roomId);
65-
addToGroup(audId + ":private", audBack.roomId);
63+
const audSlug = await audBack.getSlug();
64+
addToGroup(audSlug + ":*", audBack.roomId);
65+
addToGroup(audSlug + ":private", audBack.roomId);
6666
addToGroup("private", audBack.roomId);
6767
addToGroup("*", audBack.roomId);
6868
}
6969

7070
for (const talk of conference.storedTalks) {
7171
addToGroup("talk", talk.roomId);
72-
const audId = await talk.getAuditoriumId();
73-
addToGroup(audId + ":talk", talk.roomId);
74-
addToGroup(audId + ":*", talk.roomId);
75-
addToGroup(audId + ":private", talk.roomId);
72+
const audSlug = await conference.getAuditorium(await talk.getAuditoriumId()).getSlug();
73+
addToGroup(audSlug + ":talk", talk.roomId);
74+
addToGroup(audSlug + ":*", talk.roomId);
75+
addToGroup(audSlug + ":private", talk.roomId);
7676
addToGroup("private", talk.roomId);
7777
addToGroup("*", talk.roomId);
7878
}
@@ -86,14 +86,35 @@ export class InviteMeCommand implements ICommand {
8686
return groups;
8787
}
8888

89+
/**
90+
* Render a (somewhat) pretty list of group names.
91+
*/
92+
private prettyGroupNameList(roomGroups: Map<string, Set<string>>) {
93+
const bySection = new Map<string, string[]>();
94+
95+
// organise the groups into sections
96+
Array.from(roomGroups.keys()).forEach(group => {
97+
const section = group.split(":")[0];
98+
if (!bySection.has(section)) {
99+
bySection.set(section, []);
100+
}
101+
bySection.get(section)!.push(group);
102+
});
103+
104+
const sections = Array.from(bySection.entries());
105+
sections.sort(([aSection], [bSection]) => aSection.localeCompare(bSection));
106+
107+
return "<ul>" + sections.map(([_sectionName, groups]) => {
108+
groups.sort();
109+
return "<li>" + groups.map(x => `<code>${x}</code>`).join(", ") + "</li>";
110+
}).join("\n") + "</ul>";
111+
}
112+
89113
public async run(conference: Conference, client: MatrixClient, roomId: string, event: any, args: string[]) {
90114
const roomGroups = await this.roomGroups(conference);
91115

92116
if (!args.length) {
93-
const groupNames = Array.from(roomGroups.keys());
94-
groupNames.sort();
95-
96-
return client.replyNotice(roomId, event, "Please specify a room ID or alias, or one of the room groups: " + groupNames.join(", "));
117+
return client.replyHtmlNotice(roomId, event, "Please specify a room ID or alias, or one of the room groups:\n" + this.prettyGroupNameList(roomGroups));
97118
}
98119
const userId = args[1] || event['sender'];
99120

src/commands/StatusCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Scheduler } from "../Scheduler";
2121
import config from "../config";
2222

2323
export class StatusCommand implements ICommand {
24-
public readonly prefixes = ["status", "stat"];
24+
public readonly prefixes = ["status", "stat", "refresh"];
2525

2626
public async run(conference: Conference, client: MatrixClient, roomId: string, event: any, args: string[]) {
2727
let html = "<h4>Conference Bot Status</h4>";

0 commit comments

Comments
 (0)