From 6053370e2eebcd287238ca0d93bafe91f4de768f Mon Sep 17 00:00:00 2001 From: Boris Safonov Date: Fri, 27 Sep 2024 16:18:46 +0300 Subject: [PATCH 1/2] fix: Active speaker highlighting --- .../com/wire/kalium/logic/data/call/CallMetadataProfile.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallMetadataProfile.kt b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallMetadataProfile.kt index c8c18073978..96fd1f2d914 100644 --- a/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallMetadataProfile.kt +++ b/data/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallMetadataProfile.kt @@ -50,7 +50,7 @@ data class CallMetadata( ) { fun getFullParticipants(): List = participants.map { participant -> val user = users.firstOrNull { it.id == participant.userId } - val isSpeaking = (activeSpeakers[participant.id]?.contains(participant.clientId) ?: false) && !participant.isMuted + val isSpeaking = (activeSpeakers[participant.userId]?.contains(participant.clientId) ?: false) && !participant.isMuted Participant( id = participant.id, clientId = participant.clientId, From ce766e11298e05a344a9b3f8c4c2bab5f382c7fa Mon Sep 17 00:00:00 2001 From: Boris Safonov Date: Mon, 30 Sep 2024 13:47:06 +0300 Subject: [PATCH 2/2] Added tests --- .../logic/data/call/CallRepositoryTest.kt | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/CallRepositoryTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/CallRepositoryTest.kt index 8ac2fed6636..8ed14ad1929 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/CallRepositoryTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/CallRepositoryTest.kt @@ -82,6 +82,7 @@ import kotlinx.coroutines.test.runTest import kotlinx.coroutines.yield import kotlinx.datetime.Clock import kotlin.test.Test +import kotlin.test.assertContains import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -1474,6 +1475,56 @@ class CallRepositoryTest { assertEquals(activeSpeakers, callRepository.getCallMetadataProfile().data[Arrangement.conversationId]?.activeSpeakers) } + @Test + fun givenCallWithActiveSpeakers_whenGetFullParticipants_thenOnlySpeakingUsers() = runTest { + val (_, callRepository) = Arrangement().arrange() + val mutedParticipant = ParticipantMinimized( + id = QualifiedID("participantId", ""), + userId = QualifiedID("participantId", "participantDomain"), + clientId = "abcd0", + isMuted = true, + isCameraOn = false, + isSharingScreen = false, + hasEstablishedAudio = true + ) + val unMutedParticipant = mutedParticipant.copy( + id = QualifiedID("anotherParticipantId", ""), + userId = QualifiedID("anotherParticipantId", "participantDomain"), + clientId = "abcd1", + isMuted = false + ) + val activeSpeakers = mapOf( + mutedParticipant.userId to listOf(mutedParticipant.clientId), + unMutedParticipant.userId to listOf(unMutedParticipant.clientId), + ) + + callRepository.updateCallMetadataProfileFlow( + callMetadataProfile = CallMetadataProfile( + data = mapOf( + Arrangement.conversationId to createCallMetadata().copy( + participants = listOf(mutedParticipant, unMutedParticipant), + maxParticipants = 0 + ) + ) + ) + ) + + // when + callRepository.updateParticipantsActiveSpeaker(Arrangement.conversationId, activeSpeakers) + + // then + val fullParticipants = callRepository.getCallMetadataProfile().data[Arrangement.conversationId]?.getFullParticipants() + + assertEquals( + false, + fullParticipants?.first { it.id == mutedParticipant.id && it.clientId == mutedParticipant.clientId }?.isSpeaking + ) + assertEquals( + true, + fullParticipants?.first { it.id == unMutedParticipant.id && it.clientId == unMutedParticipant.clientId }?.isSpeaking + ) + } + private fun provideCall(id: ConversationId, status: CallStatus) = Call( conversationId = id, status = status,