Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark the attendance command as broken & make a minor attempt to fix stored person overrides #247

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 31 additions & 10 deletions src/Conference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
} from "./models/room_state";
import { applySuffixRules, objectFastClone, safeCreateRoom } from "./utils";
import { addAndDeleteManagedAliases, applyAllAliasPrefixes, assignAliasVariations, calculateAliasVariations } from "./utils/aliases";
import { IConfig } from "./config";
import { IConfig, RunMode } from "./config";
import { MatrixRoom } from "./models/MatrixRoom";
import { Auditorium, AuditoriumBackstage } from "./models/Auditorium";
import { Talk } from "./models/Talk";
Expand Down Expand Up @@ -101,7 +101,8 @@
// On any member event, recaulculate the membership.
this.enqueueRecalculateRoomMembership(roomId);

if (event['content']?.['third_party_invite']) {
// Only process 3pid invites when running as the bot, not the web interface
if (event['content']?.['third_party_invite'] && config.mode === RunMode.normal) {
const emailInviteToken = event['content']['third_party_invite']['signed']?.['token'];
const emailInvite = await this.client.getRoomStateEvent(roomId, "m.room.third_party_invite", emailInviteToken);
if (emailInvite[RS_3PID_PERSON_ID]) {
Expand All @@ -117,12 +118,11 @@
const people = await this.findPeopleWithId(emailInvite[RS_3PID_PERSON_ID]);
if (people?.length) {
// Finally, associate the users.
for (const person of people) {
const clonedPerson = objectFastClone(person);
clonedPerson.matrix_id = event['state_key'];
await this.createUpdatePerson(clonedPerson);
LogService.info("Conference", `Updated ${clonedPerson.id} to be associated with ${clonedPerson.matrix_id}`);
}
let person = people[0];
const clonedPerson = objectFastClone(person);
clonedPerson.matrix_id = event['state_key'];
await this.createUpdatePerson(clonedPerson);
LogService.info("Conference", `Updated ${clonedPerson.id} to be associated with ${clonedPerson.matrix_id}`);

// Update permissions while we're here (if we can identify the room kind)
const aud = this.storedAuditoriums.find(a => a.roomId === roomId);
Expand Down Expand Up @@ -875,10 +875,31 @@
}

/**
* @deprecated This always returns `[]` and should be removed or fixed.
* Return a list of all people with the given person ID.
*
* TODO does not support interest rooms
*/
public async findPeopleWithId(personId: string): Promise<IPerson[]> {
return [];
let out: IPerson[] = [];

for (let auditorium of Object.values(this.auditoriums)) {
let audDef = auditorium.getDefinition();
for (let talk of audDef.talks.values()) {

Check failure on line 887 in src/Conference.ts

View workflow job for this annotation

GitHub Actions / Build JSONSchema, TypeScript and Web

Property 'talks' does not exist on type 'Promise<IAuditorium>'.
for (let person of talk.speakers) {
if (person.id === personId) {
out.push(person);
}
}
}

for (let person of audDef.extraPeople) {

Check failure on line 895 in src/Conference.ts

View workflow job for this annotation

GitHub Actions / Build JSONSchema, TypeScript and Web

Property 'extraPeople' does not exist on type 'Promise<IAuditorium>'.
if (person.id === personId) {
out.push(person);
}
}
}

return out;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion src/commands/AttendanceCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { COLOR_GREEN, COLOR_RED } from "../models/colors";
import { IPerson } from "../models/schedule";
import { ConferenceMatrixClient } from "../ConferenceMatrixClient";

const BROKEN_WARNING = "<a href='https://github.com/matrix-org/conference-bot/issues/245'>This command is somewhat broken/misleading.</a> Accepted = percentage of invites that are Matrix and accepted. Emails = percentage of invites that are e-mail (regardless of whether they are accepted or not).";

export class AttendanceCommand implements ICommand {
public readonly prefixes = ["attendance"];

Expand All @@ -46,16 +48,22 @@ export class AttendanceCommand implements ICommand {
}
}

let html = "<ul>";
let html = BROKEN_WARNING + "<ul>";
const append = async (invitePeople: IPerson[], bsPeople: IPerson[] | null, name: string, roomId: string, bsRoomId: string | null, withHtml: boolean) => {
// all persons that are to be invited to this room
const inviteTargets = await resolveIdentifiers(this.client, invitePeople);

// all Matrix members of the room
const joinedMembers = await this.client.getJoinedRoomMembers(roomId);

// all invite targets that were e-mail invited, by virtue of not having a registered MXID
const emailInvites = inviteTargets.filter(i => !i.mxid).length;
// all Matrix targets that have also joined
const joined = inviteTargets.filter(i => i.mxid && joinedMembers.includes(i.mxid)).length;

// percentage of invites that are both Matrix and accepted
const acceptedPct = Math.round((joined / inviteTargets.length) * 100);
// percentage of invites that are e-mail invites. Regardless of whether they are accepted.
const emailPct = Math.round((emailInvites / inviteTargets.length) * 100);

totalInvites += inviteTargets.length;
Expand Down
Loading