Skip to content

Commit

Permalink
Be specific about what is considered a MSC4143 call member event. (#4328
Browse files Browse the repository at this point in the history
)

* Be specific about what is considered a MSC4143 call member event.

* review

* check for empty event first

* Optimize for new session type events
If its a session type event we do not want to run two "key in" checks. We expect legacy events to be the less comment type going forward.

* awkward but necessary key count optimization
  • Loading branch information
toger5 authored Jul 25, 2024
1 parent 6b261b9 commit 0f08c00
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/matrixrtc/MatrixRTCSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,27 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
const callMemberships: CallMembership[] = [];
for (const memberEvent of callMemberEvents) {
const content = memberEvent.getContent();
const eventKeysCount = Object.keys(content).length;
// Dont even bother about empty events (saves us from costly type/"key in" checks in bigger rooms)
if (eventKeysCount === 0) continue;

let membershipContents: any[] = [];

// We first decide if its a MSC4143 event (per device state key)
if ("memberships" in content) {
if (eventKeysCount > 1 && "focus_active" in content) {
// We have a MSC4143 event membership event
membershipContents.push(content);
} else if (eventKeysCount === 1 && "memberships" in content) {
// we have a legacy (one event for all devices) event
if (!Array.isArray(content["memberships"])) {
logger.warn(`Malformed member event from ${memberEvent.getSender()}: memberships is not an array`);
continue;
}
membershipContents = content["memberships"];
} else {
// We have a MSC4143 event membership event
if (Object.keys(content).length !== 0) {
// We checked for empty content to not try to construct CallMembership's with {}.
membershipContents.push(content);
}
}
if (membershipContents.length === 0) {
continue;
}

if (membershipContents.length === 0) continue;

for (const membershipData of membershipContents) {
try {
const membership = new CallMembership(memberEvent, membershipData);
Expand Down

0 comments on commit 0f08c00

Please sign in to comment.