From 21065791a86d53fda3c478bf9853646670338dad Mon Sep 17 00:00:00 2001 From: Robert Long Date: Tue, 10 May 2022 16:58:03 -0700 Subject: [PATCH 1/2] Fix removing members in handleCallMemberEvent --- src/matrix/calls/CallHandler.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/matrix/calls/CallHandler.ts b/src/matrix/calls/CallHandler.ts index 7fbe6103..92f7314c 100644 --- a/src/matrix/calls/CallHandler.ts +++ b/src/matrix/calls/CallHandler.ts @@ -40,11 +40,15 @@ export type Options = Omit & { clock: Clock }; +function getRoomMemberKey(roomId: string, userId: string) { + return JSON.stringify(roomId)+`,`+JSON.stringify(userId); +} + export class CallHandler { // group calls by call id private readonly _calls: ObservableMap = new ObservableMap(); - // map of userId to set of conf_id's they are in - private memberToCallIds: Map> = new Map(); + // map of `"roomId","userId"` to set of conf_id's they are in + private roomMemberToCallIds: Map> = new Map(); private groupCallOptions: GroupCallOptions; private sessionId = makeId("s"); @@ -98,7 +102,7 @@ export class CallHandler { // } const callsMemberEvents = await txn.roomState.getAllForType(roomId, EventType.GroupCallMember); for (const entry of callsMemberEvents) { - this.handleCallMemberEvent(entry.event, log); + this.handleCallMemberEvent(entry.event, roomId, log); } // TODO: we should be loading the other members as well at some point })); @@ -149,7 +153,7 @@ export class CallHandler { // then update members for (const event of events) { if (event.type === EventType.GroupCallMember) { - this.handleCallMemberEvent(event, log); + this.handleCallMemberEvent(event, room.id, log); } } } @@ -194,8 +198,9 @@ export class CallHandler { } } - private handleCallMemberEvent(event: StateEvent, log: ILogItem) { + private handleCallMemberEvent(event: StateEvent, roomId: string, log: ILogItem) { const userId = event.state_key; + const roomMemberKey = getRoomMemberKey(roomId, userId) const calls = event.content["m.calls"] ?? []; for (const call of calls) { const callId = call["m.call_id"]; @@ -204,7 +209,8 @@ export class CallHandler { groupCall?.updateMembership(userId, call, log); }; const newCallIdsMemberOf = new Set(calls.map(call => call["m.call_id"])); - let previousCallIdsMemberOf = this.memberToCallIds.get(userId); + let previousCallIdsMemberOf = this.roomMemberToCallIds.get(roomMemberKey); + // remove user as member of any calls not present anymore if (previousCallIdsMemberOf) { for (const previousCallId of previousCallIdsMemberOf) { @@ -215,9 +221,9 @@ export class CallHandler { } } if (newCallIdsMemberOf.size === 0) { - this.memberToCallIds.delete(userId); + this.roomMemberToCallIds.delete(roomMemberKey); } else { - this.memberToCallIds.set(userId, newCallIdsMemberOf); + this.roomMemberToCallIds.set(roomMemberKey, newCallIdsMemberOf); } } } From 5ee4e39bc78eb2ab28b7c7ac26379fd219ec8195 Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Wed, 11 May 2022 10:06:05 +0200 Subject: [PATCH 2/2] add return type --- src/matrix/calls/CallHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/matrix/calls/CallHandler.ts b/src/matrix/calls/CallHandler.ts index 92f7314c..07ed8492 100644 --- a/src/matrix/calls/CallHandler.ts +++ b/src/matrix/calls/CallHandler.ts @@ -40,7 +40,7 @@ export type Options = Omit & { clock: Clock }; -function getRoomMemberKey(roomId: string, userId: string) { +function getRoomMemberKey(roomId: string, userId: string): string { return JSON.stringify(roomId)+`,`+JSON.stringify(userId); }