From 9f768b079f2f8a7ee53e072b9e467ebaad75dea5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:23:04 +0000 Subject: [PATCH] fix: is user speaking mapper causes a flash briefly (#2809) (#2855) (#2859) (cherry picked from commit 94a64c447637c2bd3fc29c2279faa4d292b40f2d) Co-authored-by: Mohamad Jaara --- .../data/call/mapper/ActiveSpeakerMapper.kt | 2 +- .../data/call/ActiveSpeakerMapperTest.kt | 101 +++++++++++++++++- 2 files changed, 100 insertions(+), 3 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/mapper/ActiveSpeakerMapper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/mapper/ActiveSpeakerMapper.kt index e49354c2544..12eeba64952 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/mapper/ActiveSpeakerMapper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/mapper/ActiveSpeakerMapper.kt @@ -38,7 +38,7 @@ class ActiveSpeakerMapperImpl : ActiveSpeakerMapper { activeSpeaker.userId == participant.id.toString() && activeSpeaker.clientId == participant.clientId }?.let { this[indexOf(it)] = it.copy( - isSpeaking = activeSpeaker.audioLevel > 0 && activeSpeaker.audioLevelNow > 0 + isSpeaking = activeSpeaker.audioLevel > 0 || activeSpeaker.audioLevelNow > 0 ) } } diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/ActiveSpeakerMapperTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/ActiveSpeakerMapperTest.kt index 559e976d98f..0f73c360413 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/ActiveSpeakerMapperTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/ActiveSpeakerMapperTest.kt @@ -29,7 +29,7 @@ class ActiveSpeakerMapperTest { private val activeSpeakerMapper = ActiveSpeakerMapperImpl() @Test - fun givenCallActiveSpeakers_whenMappingToParticipantsActiveSpeaker_thenReturnParticipantsActiveSpeaker() = runTest { + fun givenUserAudioLevelNot0AndaudioLevelNowNot0_whenMapping_thenUserIsSpeaking() = runTest { val dummyParticipantWithDifferentClientId = DUMMY_PARTICIPANT.copy( clientId = "anotherClientId" ) @@ -40,7 +40,10 @@ class ActiveSpeakerMapperTest { dummyParticipantWithDifferentClientId ), activeSpeakers = CallActiveSpeakers( - activeSpeakers = listOf(DUMMY_CALL_ACTIVE_SPEAKER, DUMMY_CALL_ACTIVE_SPEAKER1) + activeSpeakers = listOf( + DUMMY_CALL_ACTIVE_SPEAKER.copy(audioLevel = 1, audioLevelNow = 1), + DUMMY_CALL_ACTIVE_SPEAKER1.copy(audioLevel = 1, audioLevelNow = 1) + ) ) ) @@ -48,6 +51,100 @@ class ActiveSpeakerMapperTest { DUMMY_PARTICIPANT.copy( isSpeaking = true ), + dummyParticipantWithDifferentClientId.copy( + isSpeaking = true + ) + ) + + assertEquals(expectedParticipantsActiveSpeaker, callActiveSpeakerMap) + } + + + @Test + fun givenUserAudioLevelIs0AndaudioLevelNowNot0_whenMapping_thenUserIsSpeaking() = runTest { + val dummyParticipantWithDifferentClientId = DUMMY_PARTICIPANT.copy( + clientId = "anotherClientId" + ) + + val callActiveSpeakerMap = activeSpeakerMapper.mapParticipantsActiveSpeaker( + participants = listOf( + DUMMY_PARTICIPANT, + dummyParticipantWithDifferentClientId + ), + activeSpeakers = CallActiveSpeakers( + activeSpeakers = listOf( + DUMMY_CALL_ACTIVE_SPEAKER.copy(audioLevel = 0, audioLevelNow = 1), + DUMMY_CALL_ACTIVE_SPEAKER1.copy(audioLevel = 0, audioLevelNow = 1) + ) + ) + ) + + val expectedParticipantsActiveSpeaker = listOf( + DUMMY_PARTICIPANT.copy( + isSpeaking = true + ), + dummyParticipantWithDifferentClientId.copy( + isSpeaking = true + ) + ) + + assertEquals(expectedParticipantsActiveSpeaker, callActiveSpeakerMap) + } + + @Test + fun givenUserAudioLevelNot0AndaudioLevelNowIs0_whenMapping_thenUserIsSpeaking() = runTest { + val dummyParticipantWithDifferentClientId = DUMMY_PARTICIPANT.copy( + clientId = "anotherClientId" + ) + + val callActiveSpeakerMap = activeSpeakerMapper.mapParticipantsActiveSpeaker( + participants = listOf( + DUMMY_PARTICIPANT, + dummyParticipantWithDifferentClientId + ), + activeSpeakers = CallActiveSpeakers( + activeSpeakers = listOf( + DUMMY_CALL_ACTIVE_SPEAKER.copy(audioLevel = 1, audioLevelNow = 0), + DUMMY_CALL_ACTIVE_SPEAKER1.copy(audioLevel = 1, audioLevelNow = 0) + ) + ) + ) + + val expectedParticipantsActiveSpeaker = listOf( + DUMMY_PARTICIPANT.copy( + isSpeaking = true + ), + dummyParticipantWithDifferentClientId.copy( + isSpeaking = true + ) + ) + + assertEquals(expectedParticipantsActiveSpeaker, callActiveSpeakerMap) + } + + @Test + fun givenUserAudioLevelIs0AndaudioLevelNowIs0_whenMapping_thenUserIsNotSpeaking() = runTest { + val dummyParticipantWithDifferentClientId = DUMMY_PARTICIPANT.copy( + clientId = "anotherClientId" + ) + + val callActiveSpeakerMap = activeSpeakerMapper.mapParticipantsActiveSpeaker( + participants = listOf( + DUMMY_PARTICIPANT, + dummyParticipantWithDifferentClientId + ), + activeSpeakers = CallActiveSpeakers( + activeSpeakers = listOf( + DUMMY_CALL_ACTIVE_SPEAKER.copy(audioLevel = 0, audioLevelNow = 0), + DUMMY_CALL_ACTIVE_SPEAKER1.copy(audioLevel = 0, audioLevelNow = 0) + ) + ) + ) + + val expectedParticipantsActiveSpeaker = listOf( + DUMMY_PARTICIPANT.copy( + isSpeaking = false + ), dummyParticipantWithDifferentClientId.copy( isSpeaking = false )