Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use SFT for one to one calls when needed (WPB-7153) #2893

Merged
merged 15 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package com.wire.kalium.logic.data.call
* [OneOnOne] for a 1:1 call
* [Conference] for a group cal
*/
enum class ConversationType {
enum class ConversationTypeForCall {
OneOnOne,
Conference,
ConferenceMls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import kotlin.test.BeforeTest
import kotlin.test.Ignore
import kotlin.test.Test
import com.wire.kalium.logic.feature.call.usecase.ConversationClientsInCallUpdater
import com.wire.kalium.logic.feature.call.usecase.GetCallConversationTypeProvider
import com.wire.kalium.network.NetworkStateObserver
import com.wire.kalium.util.DateTimeUtil.toIsoDateTimeString
import kotlinx.datetime.Instant
Expand Down Expand Up @@ -96,6 +97,9 @@ class CallManagerTest {
@Mock
private val networkStateObserver = mock(NetworkStateObserver::class)

@Mock
private val getCallConversationType = mock(GetCallConversationTypeProvider::class)

private val dispatcher = TestKaliumDispatcher

private lateinit var callManagerImpl: CallManagerImpl
Expand All @@ -119,6 +123,7 @@ class CallManagerTest {
qualifiedIdMapper = qualifiedIdMapper,
videoStateChecker = videoStateChecker,
callMapper = callMapper,
getCallConversationType = getCallConversationType,
conversationClientsInCallUpdater = conversationClientsInCallUpdater,
networkStateObserver = networkStateObserver,
kaliumConfigs = kaliumConfigs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package com.wire.kalium.logic.feature.call.scenario
import com.wire.kalium.calling.types.Uint32_t
import com.wire.kalium.calling.ConversationTypeCalling
import com.wire.kalium.logic.data.call.CallRepository
import com.wire.kalium.logic.data.call.ConversationType
import com.wire.kalium.logic.data.call.ConversationTypeForCall
import com.wire.kalium.logic.data.call.mapper.CallMapperImpl
import com.wire.kalium.logic.data.id.QualifiedIdMapperImpl
import com.wire.kalium.logic.data.call.CallStatus
Expand All @@ -33,7 +33,6 @@ import io.mockative.coVerify
import io.mockative.eq
import io.mockative.mock
import io.mockative.once
import io.mockative.verify
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.runTest
Expand Down Expand Up @@ -63,7 +62,7 @@ class OnIncomingCallTest {
coVerify {
arrangement.callRepository.createCall(
eq(TestConversation.CONVERSATION.id),
eq(ConversationType.Conference),
eq(ConversationTypeForCall.Conference),
eq(CallStatus.INCOMING),
eq(TestUser.USER_ID.toString()),
eq(true),
Expand Down Expand Up @@ -93,7 +92,7 @@ class OnIncomingCallTest {
coVerify {
arrangement.callRepository.createCall(
eq(TestConversation.CONVERSATION.id),
eq(ConversationType.Conference),
eq(ConversationTypeForCall.Conference),
eq(CallStatus.STILL_ONGOING),
eq(TestUser.USER_ID.toString()),
eq(true),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.wire.kalium.logic.feature.call

import com.wire.kalium.calling.ConversationTypeCalling
import com.wire.kalium.logic.data.call.CallClientList
import com.wire.kalium.logic.data.call.CallType
import com.wire.kalium.logic.data.call.EpochInfo
Expand All @@ -38,6 +39,7 @@ class CallManagerImpl : CallManager {
override suspend fun startCall(
conversationId: ConversationId,
callType: CallType,
conversationTypeCalling: ConversationTypeCalling,
isAudioCbr: Boolean
) {
TODO("Not yet implemented")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.wire.kalium.logic.data.id.QualifiedIdMapper
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.data.id.CurrentClientIdProvider
import com.wire.kalium.logic.feature.call.usecase.ConversationClientsInCallUpdater
import com.wire.kalium.logic.feature.call.usecase.GetCallConversationTypeProvider
import com.wire.kalium.logic.feature.message.MessageSender
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.network.NetworkStateObserver
Expand All @@ -51,6 +52,7 @@ actual class GlobalCallManager {
qualifiedIdMapper: QualifiedIdMapper,
videoStateChecker: VideoStateChecker,
conversationClientsInCallUpdater: ConversationClientsInCallUpdater,
getCallConversationType: GetCallConversationTypeProvider,
networkStateObserver: NetworkStateObserver,
kaliumConfigs: KaliumConfigs
): CallManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package com.wire.kalium.logic.feature.call
import com.sun.jna.Pointer
import com.wire.kalium.calling.CallTypeCalling
import com.wire.kalium.calling.Calling
import com.wire.kalium.calling.ConversationTypeCalling
import com.wire.kalium.calling.callbacks.ConstantBitRateStateChangeHandler
import com.wire.kalium.calling.callbacks.MetricsHandler
import com.wire.kalium.calling.callbacks.ReadyHandler
Expand All @@ -36,7 +37,6 @@ import com.wire.kalium.logic.data.call.CallClientList
import com.wire.kalium.logic.data.call.CallRepository
import com.wire.kalium.logic.data.call.CallStatus
import com.wire.kalium.logic.data.call.CallType
import com.wire.kalium.logic.data.call.ConversationType
import com.wire.kalium.logic.data.call.EpochInfo
import com.wire.kalium.logic.data.call.Participant
import com.wire.kalium.logic.data.call.TestVideoType
Expand Down Expand Up @@ -71,6 +71,7 @@ import com.wire.kalium.logic.feature.call.scenario.OnRequestNewEpoch
import com.wire.kalium.logic.feature.call.scenario.OnSFTRequest
import com.wire.kalium.logic.feature.call.scenario.OnSendOTR
import com.wire.kalium.logic.feature.call.usecase.ConversationClientsInCallUpdater
import com.wire.kalium.logic.feature.call.usecase.GetCallConversationTypeProvider
import com.wire.kalium.logic.feature.message.MessageSender
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.logic.functional.fold
Expand Down Expand Up @@ -108,6 +109,7 @@ class CallManagerImpl internal constructor(
private val videoStateChecker: VideoStateChecker,
private val conversationClientsInCallUpdater: ConversationClientsInCallUpdater,
private val networkStateObserver: NetworkStateObserver,
private val getCallConversationType: GetCallConversationTypeProvider,
private val kaliumConfigs: KaliumConfigs,
private val mediaManagerService: MediaManagerService,
private val flowManagerService: FlowManagerService,
Expand Down Expand Up @@ -249,9 +251,8 @@ class CallManagerImpl internal constructor(
message.conversationId
}

val type = conversationRepository.getConversationById(targetConversationId)?.let {
callMapper.fromConversationToConversationType(it)
} ?: ConversationType.Unknown
val callConversationType = getCallConversationType(targetConversationId)
val type = callMapper.toConversationType(callConversationType)

wcall_recv_msg(
inst = deferredHandle.await(),
Expand All @@ -271,16 +272,15 @@ class CallManagerImpl internal constructor(
override suspend fun startCall(
conversationId: ConversationId,
callType: CallType,
conversationTypeCalling: ConversationTypeCalling,
isAudioCbr: Boolean
) {
callingLogger.d(
"$TAG -> starting call for conversation = " +
"${conversationId.toLogString()}.."
)
val isCameraOn = callType == CallType.VIDEO
val type = conversationRepository.getConversationById(conversationId)?.let {
callMapper.fromConversationToConversationType(it)
} ?: ConversationType.Unknown
val type = callMapper.toConversationType(conversationTypeCalling)

callRepository.createCall(
conversationId = conversationId,
Expand All @@ -294,13 +294,12 @@ class CallManagerImpl internal constructor(

withCalling {
val avsCallType = callMapper.toCallTypeCalling(callType)
val avsConversationType = callMapper.toConversationTypeCalling(type)
// TODO: Handle response. Possible failure?
wcall_start(
deferredHandle.await(),
federatedIdMapper.parseToFederatedId(conversationId),
avsCallType.avsValue,
avsConversationType.avsValue,
conversationTypeCalling.avsValue,
isAudioCbr.toInt()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import com.wire.kalium.logic.data.id.QualifiedIdMapper
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.feature.call.usecase.ConversationClientsInCallUpdater
import com.wire.kalium.logic.feature.call.usecase.GetCallConversationTypeProvider
import com.wire.kalium.logic.feature.message.MessageSender
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.logic.util.CurrentPlatform
Expand Down Expand Up @@ -88,6 +89,7 @@ actual class GlobalCallManager(
qualifiedIdMapper: QualifiedIdMapper,
videoStateChecker: VideoStateChecker,
conversationClientsInCallUpdater: ConversationClientsInCallUpdater,
getCallConversationType: GetCallConversationTypeProvider,
networkStateObserver: NetworkStateObserver,
kaliumConfigs: KaliumConfigs
): CallManager {
Expand All @@ -105,6 +107,7 @@ actual class GlobalCallManager(
qualifiedIdMapper = qualifiedIdMapper,
videoStateChecker = videoStateChecker,
conversationClientsInCallUpdater = conversationClientsInCallUpdater,
getCallConversationType = getCallConversationType,
networkStateObserver = networkStateObserver,
mediaManagerService = mediaManager,
flowManagerService = flowManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.wire.kalium.logger.obfuscateId
import com.wire.kalium.logic.callingLogger
import com.wire.kalium.logic.data.call.mapper.CallMapper
import com.wire.kalium.logic.data.call.CallRepository
import com.wire.kalium.logic.data.call.ConversationType
import com.wire.kalium.logic.data.call.ConversationTypeForCall
import com.wire.kalium.logic.data.id.QualifiedIdMapper
import com.wire.kalium.logic.data.call.CallStatus
import com.wire.kalium.logic.featureFlags.KaliumConfigs
Expand Down Expand Up @@ -55,7 +55,7 @@ class OnIncomingCall(
" | UserId: ${userId.obfuscateId()} | shouldRing: $shouldRing | type: $conversationType"
)
val mappedConversationType = callMapper.fromIntToConversationType(conversationType)
val isMuted = setOf(ConversationType.Conference, ConversationType.ConferenceMls).contains(mappedConversationType)
val isMuted = setOf(ConversationTypeForCall.Conference, ConversationTypeForCall.ConferenceMls).contains(mappedConversationType)
val status = if (shouldRing) CallStatus.INCOMING else CallStatus.STILL_ONGOING
val qualifiedConversationId = qualifiedIdMapper.fromStringToQualifiedID(conversationId)
scope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ interface CallRepository {
@Suppress("LongParameterList")
suspend fun createCall(
conversationId: ConversationId,
type: ConversationType,
type: ConversationTypeForCall,
status: CallStatus,
callerId: String,
isMuted: Boolean,
Expand Down Expand Up @@ -189,7 +189,7 @@ internal class CallDataSource(
@Suppress("LongMethod", "NestedBlockDepth")
override suspend fun createCall(
conversationId: ConversationId,
type: ConversationType,
type: ConversationTypeForCall,
status: CallStatus,
callerId: String,
isMuted: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.wire.kalium.calling.VideoStateCalling
import com.wire.kalium.logic.data.call.CallClientList
import com.wire.kalium.logic.data.call.CallMetadata
import com.wire.kalium.logic.data.call.CallType
import com.wire.kalium.logic.data.call.ConversationType
import com.wire.kalium.logic.data.call.ConversationTypeForCall
import com.wire.kalium.logic.data.call.VideoState
import com.wire.kalium.logic.data.conversation.ClientId
import com.wire.kalium.logic.data.conversation.Conversation
Expand All @@ -41,17 +41,21 @@ import com.wire.kalium.persistence.dao.conversation.ConversationEntity

interface CallMapper {
fun toCallTypeCalling(callType: CallType): CallTypeCalling
fun toConversationTypeCalling(conversationType: ConversationType): ConversationTypeCalling
fun fromIntToConversationType(conversationType: Int): ConversationType
fun toConversationTypeCalling(conversationTypeForCall: ConversationTypeForCall): ConversationTypeCalling
fun toConversationType(conversationTypeCalling: ConversationTypeCalling): ConversationTypeForCall
fun fromIntToConversationType(conversationType: Int): ConversationTypeForCall
fun fromIntToCallingVideoState(videStateInt: Int): VideoStateCalling
fun toVideoStateCalling(videoState: VideoState): VideoStateCalling
fun fromConversationToConversationType(conversation: Conversation): ConversationType
fun fromConversationTypeToConversationTypeForCall(
conversationType: Conversation.Type,
conversationProtocol: Conversation.ProtocolInfo
): ConversationTypeForCall

@Suppress("LongParameterList")
fun toCallEntity(
conversationId: ConversationId,
id: String,
type: ConversationType,
type: ConversationTypeForCall,
status: CallStatus,
conversationType: Conversation.Type,
callerId: UserId
Expand Down Expand Up @@ -81,21 +85,30 @@ class CallMapperImpl(
}
}

override fun toConversationTypeCalling(conversationType: ConversationType): ConversationTypeCalling {
return when (conversationType) {
ConversationType.OneOnOne -> ConversationTypeCalling.OneOnOne
ConversationType.Conference -> ConversationTypeCalling.Conference
ConversationType.ConferenceMls -> ConversationTypeCalling.ConferenceMls
override fun toConversationTypeCalling(conversationTypeForCall: ConversationTypeForCall): ConversationTypeCalling {
return when (conversationTypeForCall) {
ConversationTypeForCall.OneOnOne -> ConversationTypeCalling.OneOnOne
ConversationTypeForCall.Conference -> ConversationTypeCalling.Conference
ConversationTypeForCall.ConferenceMls -> ConversationTypeCalling.ConferenceMls
else -> ConversationTypeCalling.Unknown
}
}

override fun fromIntToConversationType(conversationType: Int): ConversationType {
override fun toConversationType(conversationTypeCalling: ConversationTypeCalling): ConversationTypeForCall {
return when (conversationTypeCalling) {
ConversationTypeCalling.OneOnOne -> ConversationTypeForCall.OneOnOne
ConversationTypeCalling.Conference -> ConversationTypeForCall.Conference
ConversationTypeCalling.ConferenceMls -> ConversationTypeForCall.ConferenceMls
else -> ConversationTypeForCall.Unknown
}
}

override fun fromIntToConversationType(conversationType: Int): ConversationTypeForCall {
return when (conversationType) {
ConversationTypeCalling.OneOnOne.avsValue -> ConversationType.OneOnOne
ConversationTypeCalling.Conference.avsValue -> ConversationType.Conference
ConversationTypeCalling.ConferenceMls.avsValue -> ConversationType.ConferenceMls
else -> ConversationType.Unknown
ConversationTypeCalling.OneOnOne.avsValue -> ConversationTypeForCall.OneOnOne
ConversationTypeCalling.Conference.avsValue -> ConversationTypeForCall.Conference
ConversationTypeCalling.ConferenceMls.avsValue -> ConversationTypeForCall.ConferenceMls
else -> ConversationTypeForCall.Unknown
}
}

Expand All @@ -120,23 +133,26 @@ class CallMapperImpl(
VideoState.UNKNOWN -> VideoStateCalling.UNKNOWN
}

override fun fromConversationToConversationType(conversation: Conversation): ConversationType =
when (conversation.type) {
override fun fromConversationTypeToConversationTypeForCall(
conversationType: Conversation.Type,
conversationProtocol: Conversation.ProtocolInfo
): ConversationTypeForCall =
when (conversationType) {
Conversation.Type.GROUP -> {
when (conversation.protocol) {
is Conversation.ProtocolInfo.MLS -> ConversationType.ConferenceMls
when (conversationProtocol) {
is Conversation.ProtocolInfo.MLS -> ConversationTypeForCall.ConferenceMls
is Conversation.ProtocolInfo.Proteus,
is Conversation.ProtocolInfo.Mixed -> ConversationType.Conference
is Conversation.ProtocolInfo.Mixed -> ConversationTypeForCall.Conference
}
}
Conversation.Type.ONE_ON_ONE -> ConversationType.OneOnOne
else -> ConversationType.Unknown
Conversation.Type.ONE_ON_ONE -> ConversationTypeForCall.OneOnOne
else -> ConversationTypeForCall.Unknown
}

override fun toCallEntity(
conversationId: ConversationId,
id: String,
type: ConversationType,
type: ConversationTypeForCall,
status: CallStatus,
conversationType: Conversation.Type,
callerId: UserId
Expand Down Expand Up @@ -179,11 +195,11 @@ class CallMapperImpl(
else -> ConversationEntity.Type.ONE_ON_ONE
}

private fun toCallEntityType(conversationType: ConversationType): CallEntity.Type = when (conversationType) {
ConversationType.OneOnOne -> CallEntity.Type.ONE_ON_ONE
ConversationType.Conference -> CallEntity.Type.CONFERENCE
ConversationType.ConferenceMls -> CallEntity.Type.MLS_CONFERENCE
ConversationType.Unknown -> CallEntity.Type.UNKNOWN
private fun toCallEntityType(conversationTypeForCall: ConversationTypeForCall): CallEntity.Type = when (conversationTypeForCall) {
ConversationTypeForCall.OneOnOne -> CallEntity.Type.ONE_ON_ONE
ConversationTypeForCall.Conference -> CallEntity.Type.CONFERENCE
ConversationTypeForCall.ConferenceMls -> CallEntity.Type.MLS_CONFERENCE
ConversationTypeForCall.Unknown -> CallEntity.Type.UNKNOWN
}

override fun toConversationType(conversationType: ConversationEntity.Type): Conversation.Type = when (conversationType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ interface ConversationMapper {
fun verificationStatusFromEntity(verificationStatus: ConversationEntity.VerificationStatus): Conversation.VerificationStatus
fun legalHoldStatusToEntity(legalHoldStatus: Conversation.LegalHoldStatus): ConversationEntity.LegalHoldStatus
fun legalHoldStatusFromEntity(legalHoldStatus: ConversationEntity.LegalHoldStatus): Conversation.LegalHoldStatus

fun fromConversationEntityType(type: ConversationEntity.Type): Conversation.Type
}

@Suppress("TooManyFunctions", "LongParameterList")
Expand Down Expand Up @@ -454,6 +456,10 @@ internal class ConversationMapperImpl(
ConversationEntity.LegalHoldStatus.DEGRADED -> Conversation.LegalHoldStatus.DEGRADED
ConversationEntity.LegalHoldStatus.DISABLED -> Conversation.LegalHoldStatus.DISABLED
}

override fun fromConversationEntityType(type: ConversationEntity.Type): Conversation.Type {
return type.fromDaoModelToType()
}
}

internal fun ConversationResponse.toConversationType(selfUserTeamId: TeamId?): ConversationEntity.Type {
Expand Down
Loading
Loading