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 )