From f010b515133e2167fbbe47183e1d6d0c512ef246 Mon Sep 17 00:00:00 2001 From: td Date: Sun, 12 May 2024 21:35:38 +0530 Subject: [PATCH] fix: group call voipIds not considering backend, application and scope --- lib/src/voip/models/voip_id.dart | 35 ++++++++++++------- .../voip/utils/famedly_call_extension.dart | 11 ++++++ lib/src/voip/voip.dart | 22 ++++++------ 3 files changed, 44 insertions(+), 24 deletions(-) diff --git a/lib/src/voip/models/voip_id.dart b/lib/src/voip/models/voip_id.dart index 19523b4b5..b0a1241db 100644 --- a/lib/src/voip/models/voip_id.dart +++ b/lib/src/voip/models/voip_id.dart @@ -1,24 +1,33 @@ class VoipId { final String roomId; final String callId; + final String? callBackendType; + final String? application; + final String? scope; - String get id => '$roomId:$callId'; - - factory VoipId.fromId(String id) { - final int lastIndex = id.lastIndexOf(':'); - return VoipId( - roomId: id.substring(0, lastIndex), - callId: id.substring(lastIndex + 1), - ); - } - - VoipId({required this.roomId, required this.callId}); + VoipId({ + required this.roomId, + required this.callId, + this.callBackendType, + this.application, + this.scope, + }); @override bool operator ==(Object other) => identical(this, other) || - other is VoipId && roomId == other.roomId && callId == other.callId; + other is VoipId && + roomId == other.roomId && + callId == other.callId && + callBackendType == other.callBackendType && + application == other.application && + scope == other.scope; @override - int get hashCode => roomId.hashCode ^ callId.hashCode; + int get hashCode => + roomId.hashCode ^ + callId.hashCode ^ + callBackendType.hashCode ^ + application.hashCode ^ + scope.hashCode; } diff --git a/lib/src/voip/utils/famedly_call_extension.dart b/lib/src/voip/utils/famedly_call_extension.dart index 0f7b6d4a5..591a29e84 100644 --- a/lib/src/voip/utils/famedly_call_extension.dart +++ b/lib/src/voip/utils/famedly_call_extension.dart @@ -40,6 +40,17 @@ extension FamedlyCallMemberEventsExtension on Room { return mem ?? []; } + /// returns a list of memberships in the room for `callParticipant` + List getCallMembershipsForUserWithDeviceId( + CallParticipant callParticipant, + ) { + final userMems = getCallMembershipsForUser(callParticipant.userId); + final mem = userMems + .where((element) => element.deviceId == callParticipant.deviceId) + .toList(); + return mem; + } + /// returns the user count (not sessions, yet) for the group call with id: `groupCallId`. /// returns 0 if group call not found int groupCallParticipantCount(String groupCallId) { diff --git a/lib/src/voip/voip.dart b/lib/src/voip/voip.dart index 6d381a7a4..1a0833579 100644 --- a/lib/src/voip/voip.dart +++ b/lib/src/voip/voip.dart @@ -729,11 +729,6 @@ class VoIP { String? application, String? scope, ) async { - if (getGroupCallById(room.id, groupCallId) != null) { - Logs().v('[VOIP] [$groupCallId] already exists.'); - return getGroupCallById(room.id, groupCallId)!; - } - final groupCall = GroupCallSession( groupCallId: groupCallId, client: client, @@ -764,14 +759,21 @@ class VoIP { String? application, String? scope, ) async { - final groupCall = getGroupCallById(room.id, groupCallId); + final existingGroupCall = getGroupCallById(VoipId( + roomId: room.id, + callId: groupCallId, + callBackendType: backend.type, + application: application, + scope: scope, + )); - if (groupCall != null) { + if (existingGroupCall != null) { if (!room.canJoinGroupCall) { throw Exception( 'User is not allowed to join famedly calls in the room'); } - return groupCall; + Logs().v('[VOIP] [$groupCallId] already exists.'); + return existingGroupCall; } if (!room.groupCallsEnabledForEveryone) { @@ -788,9 +790,7 @@ class VoIP { ); } - GroupCallSession? getGroupCallById(String roomId, String groupCallId) { - return groupCalls[VoipId(roomId: roomId, callId: groupCallId)]; - } + GroupCallSession? getGroupCallById(VoipId voipId) => groupCalls[voipId]; void setGroupCallById(GroupCallSession groupCallSession) { groupCalls[VoipId(