Skip to content

Commit

Permalink
Add Orchestration room to room attendant spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKvalheim committed Oct 25, 2024
1 parent a3d2480 commit f6184cd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
1 change: 1 addition & 0 deletions data/plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ rooms:
name: Orchestration
topic: >-
Ready your batons! The SeaGL 2024 control-center.
inviteAttendants: true
SeaGL2024-Volunteers:
tag: seagl2024-volunteers
name: Volunteers
Expand Down
1 change: 1 addition & 0 deletions src/lib/Plan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export namespace Plan {
control?: boolean;
destroy?: boolean;
intro?: string;
inviteAttendants?: boolean;
moderatorsOnly?: boolean;
name: string;
private?: boolean;
Expand Down
44 changes: 32 additions & 12 deletions src/modules/Reconciler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default class extends Module {
#scheduledReconcile: Scheduled | undefined;
#scheduledRegroups: Map<Room["id"], Scheduled>;
#sessionGroups: { [id in SessionGroupId]?: ListedSpace };
#sharedWithAttendants: Map<Room["id"], Room>;

public constructor(
patch: Patch,
Expand All @@ -90,6 +91,7 @@ export default class extends Module {
this.#roomByTag = new Map();
this.#scheduledRegroups = new Map();
this.#sessionGroups = {};
this.#sharedWithAttendants = new Map();
}

public getPublicParent(child: string): string | undefined {
Expand Down Expand Up @@ -479,19 +481,23 @@ export default class extends Module {
}

private async reconcileInvitations(child: Room, parent?: Room) {
if (!child.private) return;
if (!(child.private || parent?.private)) return;

this.debug("🛡️ List moderators", { room: (parent ?? child).local });
const moderators = await this.getModerators((parent ?? child).id);

const extra = [];
if (child.inviteAttendants)
extra.push(...Object.values(this.plan.roomAttendants ?? {}));

this.debug("🚪 Get memberships", { room: child.local });
const childMemberships = await this.matrix.getRoomMembers(child.id);

for (const { membership, membershipFor: invitee, sender } of childMemberships) {
if (
membership === "invite" &&
sender === this.plan.steward.id &&
!moderators.includes(invitee)
!(moderators.includes(invitee) || extra.includes(invitee))
) {
this.info("🎟️ Withdraw invitation", { room: child.local, invitee });
await this.matrix.sendStateEvent(child.id, "m.room.member", invitee, {
Expand All @@ -503,16 +509,26 @@ export default class extends Module {
if (parent) this.debug("🚪 Get memberships", { space: parent.local });
const parentMemberships = parent && (await this.matrix.getRoomMembers(parent.id));

for (const invitee of moderators) {
const childMembership = childMemberships.find((m) => m.membershipFor === invitee);
if (child.private) {
for (const invitee of moderators) {
const childMembership = childMemberships.find((m) => m.membershipFor === invitee);
if (
(!parentMemberships ||
parentMemberships.some(
(m) => m.membershipFor === invitee && m.membership === "join",
)) &&
(!childMembership ||
(childMembership.membership === "leave" &&
childMembership.sender === this.plan.steward.id))
)
await this.tryInvite(child.id, child.local, invitee);
}
}
for (const invitee of extra) {
const membership = childMemberships.find((m) => m.membershipFor === invitee);
if (
(!parentMemberships ||
parentMemberships.some(
(m) => m.membershipFor === invitee && m.membership === "join",
)) &&
(!childMembership ||
(childMembership.membership === "leave" &&
childMembership.sender === this.plan.steward.id))
!membership ||
(membership.membership === "leave" && membership.sender === this.plan.steward.id)
)
await this.tryInvite(child.id, child.local, invitee);
}
Expand Down Expand Up @@ -667,6 +683,9 @@ export default class extends Module {
await this.reconcileIntro(room);
await this.reconcileRedirect(room);

if (expected.inviteAttendants) this.#sharedWithAttendants.set(id, room);
else this.#sharedWithAttendants.delete(id);

if (expected.children) {
this.debug("🏘️ Get space", { local });
const space = await this.matrix.getSpace(id);
Expand Down Expand Up @@ -785,7 +804,8 @@ export default class extends Module {
const tag = `pretalx-room-${id}`;
const local = `${plan.prefix}room-${id}`;
const invitees = optional(this.plan.roomAttendants?.[id]);
await this.reconcileView(local, { avatar: "room", name, tag }, children, invitees);
const visible = [...this.#sharedWithAttendants.values(), ...children];
await this.reconcileView(local, { avatar: "room", name, tag }, visible, invitees);
}
}

Expand Down

0 comments on commit f6184cd

Please sign in to comment.