diff --git a/logic/src/androidInstrumentedTest/kotlin/com/wire/kalium/logic/feature/call/CallManagerTest.kt b/logic/src/androidInstrumentedTest/kotlin/com/wire/kalium/logic/feature/call/CallManagerTest.kt index b26a438b05b..2e89948aefd 100644 --- a/logic/src/androidInstrumentedTest/kotlin/com/wire/kalium/logic/feature/call/CallManagerTest.kt +++ b/logic/src/androidInstrumentedTest/kotlin/com/wire/kalium/logic/feature/call/CallManagerTest.kt @@ -27,7 +27,6 @@ import com.wire.kalium.logic.data.call.VideoStateChecker import com.wire.kalium.logic.data.call.mapper.CallMapperImpl import com.wire.kalium.logic.data.conversation.ClientId import com.wire.kalium.logic.data.conversation.ConversationRepository -import com.wire.kalium.logic.data.conversation.SubconversationRepository import com.wire.kalium.logic.data.id.ConversationId import com.wire.kalium.logic.data.id.CurrentClientIdProvider import com.wire.kalium.logic.data.id.FederatedIdMapper @@ -80,9 +79,6 @@ class CallManagerTest { @Mock private val selfConversationIdProvider = mock(SelfConversationIdProvider::class) - @Mock - private val subconversationRepository = mock(SubconversationRepository::class) - @Mock private val userConfigRepository = mock(UserConfigRepository::class) @@ -124,7 +120,6 @@ class CallManagerTest { currentClientIdProvider = currentClientIdProvider, selfConversationIdProvider = selfConversationIdProvider, conversationRepository = conversationRepository, - subconversationRepository = subconversationRepository, userConfigRepository = userConfigRepository, messageSender = messageSender, kaliumDispatchers = dispatcher, diff --git a/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/call/GlobalCallManager.kt b/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/call/GlobalCallManager.kt index f51bfc60c66..1382845bf18 100644 --- a/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/call/GlobalCallManager.kt +++ b/logic/src/appleMain/kotlin/com/wire/kalium/logic/feature/call/GlobalCallManager.kt @@ -26,7 +26,6 @@ import com.wire.kalium.logic.data.call.CallRepository import com.wire.kalium.logic.data.call.VideoStateChecker import com.wire.kalium.logic.data.call.mapper.CallMapper import com.wire.kalium.logic.data.conversation.ConversationRepository -import com.wire.kalium.logic.data.conversation.SubconversationRepository import com.wire.kalium.logic.data.id.CurrentClientIdProvider import com.wire.kalium.logic.data.id.FederatedIdMapper import com.wire.kalium.logic.data.id.QualifiedID @@ -48,7 +47,6 @@ actual class GlobalCallManager { currentClientIdProvider: CurrentClientIdProvider, selfConversationIdProvider: SelfConversationIdProvider, conversationRepository: ConversationRepository, - subconversationRepository: SubconversationRepository, userConfigRepository: UserConfigRepository, messageSender: MessageSender, callMapper: CallMapper, diff --git a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/call/CallManagerImpl.kt b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/call/CallManagerImpl.kt index 21b7368464e..b76b3df56b8 100644 --- a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/call/CallManagerImpl.kt +++ b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/call/CallManagerImpl.kt @@ -49,7 +49,6 @@ import com.wire.kalium.logic.data.call.mapper.ParticipantMapperImpl import com.wire.kalium.logic.data.conversation.ClientId import com.wire.kalium.logic.data.conversation.Conversation import com.wire.kalium.logic.data.conversation.ConversationRepository -import com.wire.kalium.logic.data.conversation.SubconversationRepository import com.wire.kalium.logic.data.id.ConversationId import com.wire.kalium.logic.data.id.CurrentClientIdProvider import com.wire.kalium.logic.data.id.FederatedIdMapper @@ -114,7 +113,6 @@ class CallManagerImpl internal constructor( private val conversationClientsInCallUpdater: ConversationClientsInCallUpdater, private val networkStateObserver: NetworkStateObserver, private val getCallConversationType: GetCallConversationTypeProvider, - private val subconversationRepository: SubconversationRepository, private val userConfigRepository: UserConfigRepository, private val kaliumConfigs: KaliumConfigs, private val mediaManagerService: MediaManagerService, @@ -216,7 +214,6 @@ class CallManagerImpl internal constructor( .keepingStrongReference(), closeCallHandler = OnCloseCall( callRepository = callRepository, - callHelper = CallHelperImpl(callRepository, subconversationRepository, userConfigRepository), networkStateObserver = networkStateObserver, scope = scope, qualifiedIdMapper = qualifiedIdMapper @@ -543,11 +540,7 @@ class CallManagerImpl internal constructor( qualifiedIdMapper = qualifiedIdMapper, participantMapper = ParticipantMapperImpl(videoStateChecker, callMapper, qualifiedIdMapper), userConfigRepository = userConfigRepository, - callHelper = CallHelperImpl( - callRepository = callRepository, - subconversationRepository = subconversationRepository, - userConfigRepository = userConfigRepository - ), + callHelper = CallHelperImpl(), endCall = { endCall(it) }, callingScope = scope ).keepingStrongReference() diff --git a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/call/GlobalCallManager.kt b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/call/GlobalCallManager.kt index e2b26560e80..e485f7cff1f 100644 --- a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/call/GlobalCallManager.kt +++ b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/call/GlobalCallManager.kt @@ -31,7 +31,6 @@ import com.wire.kalium.logic.data.call.CallRepository import com.wire.kalium.logic.data.call.VideoStateChecker import com.wire.kalium.logic.data.call.mapper.CallMapper import com.wire.kalium.logic.data.conversation.ConversationRepository -import com.wire.kalium.logic.data.conversation.SubconversationRepository import com.wire.kalium.logic.data.id.CurrentClientIdProvider import com.wire.kalium.logic.data.id.FederatedIdMapper import com.wire.kalium.logic.data.id.QualifiedID @@ -85,7 +84,6 @@ actual class GlobalCallManager( currentClientIdProvider: CurrentClientIdProvider, selfConversationIdProvider: SelfConversationIdProvider, conversationRepository: ConversationRepository, - subconversationRepository: SubconversationRepository, userConfigRepository: UserConfigRepository, messageSender: MessageSender, callMapper: CallMapper, @@ -115,7 +113,6 @@ actual class GlobalCallManager( networkStateObserver = networkStateObserver, mediaManagerService = mediaManager, flowManagerService = flowManager, - subconversationRepository = subconversationRepository, userConfigRepository = userConfigRepository, kaliumConfigs = kaliumConfigs ) diff --git a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/call/scenario/OnCloseCall.kt b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/call/scenario/OnCloseCall.kt index 60aaa94012f..26d8c0b8194 100644 --- a/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/call/scenario/OnCloseCall.kt +++ b/logic/src/commonJvmAndroid/kotlin/com/wire/kalium/logic/feature/call/scenario/OnCloseCall.kt @@ -28,7 +28,6 @@ import com.wire.kalium.logger.obfuscateId import com.wire.kalium.logic.callingLogger import com.wire.kalium.logic.data.call.CallRepository import com.wire.kalium.logic.data.call.CallStatus -import com.wire.kalium.logic.data.call.CallHelper import com.wire.kalium.logic.data.conversation.Conversation import com.wire.kalium.logic.data.id.ConversationId import com.wire.kalium.logic.data.id.QualifiedIdMapper @@ -40,7 +39,6 @@ import kotlinx.coroutines.launch @Suppress("LongParameterList") class OnCloseCall( private val callRepository: CallRepository, - private val callHelper: CallHelper, private val scope: CoroutineScope, private val qualifiedIdMapper: QualifiedIdMapper, private val networkStateObserver: NetworkStateObserver @@ -65,8 +63,13 @@ class OnCloseCall( scope.launch { - val isConnectedToInternet = networkStateObserver.observeNetworkState().value == NetworkState.ConnectedWithInternet - if (shouldPersistMissedCall(conversationIdWithDomain, callStatus) && isConnectedToInternet) { + val isConnectedToInternet = + networkStateObserver.observeNetworkState().value == NetworkState.ConnectedWithInternet + if (shouldPersistMissedCall( + conversationIdWithDomain, + callStatus + ) && isConnectedToInternet + ) { callRepository.persistMissedCall(conversationIdWithDomain) } @@ -75,11 +78,8 @@ class OnCloseCall( status = callStatus ) - val conversationType = - callRepository.getCallMetadataProfile()[conversationIdWithDomain]?.conversationType - if (callRepository.getCallMetadataProfile()[conversationIdWithDomain]?.protocol is Conversation.ProtocolInfo.MLS) { - callHelper.handleCallTermination(conversationIdWithDomain, conversationType) + callRepository.leaveMlsConference(conversationIdWithDomain) } callingLogger.i("[OnCloseCall] -> ConversationId: ${conversationId.obfuscateId()} | callStatus: $callStatus") } diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallHelper.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallHelper.kt index 8759f162721..710633ab3e5 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallHelper.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/data/call/CallHelper.kt @@ -17,17 +17,8 @@ */ package com.wire.kalium.logic.data.call -import com.wire.kalium.logic.callingLogger -import com.wire.kalium.logic.configuration.UserConfigRepository import com.wire.kalium.logic.data.conversation.Conversation -import com.wire.kalium.logic.data.conversation.SubconversationRepository import com.wire.kalium.logic.data.id.ConversationId -import com.wire.kalium.logic.data.id.SubconversationId -import com.wire.kalium.logic.data.id.toModel -import com.wire.kalium.logic.functional.getOrElse -import com.wire.kalium.logic.functional.onFailure -import com.wire.kalium.logic.functional.onSuccess -import com.wire.kalium.network.api.authenticated.conversation.SubconversationDeleteRequest /** * Helper class to handle call related operations. @@ -53,27 +44,9 @@ interface CallHelper { newCallParticipants: List, previousCallParticipants: List ): Boolean - - /** - * Handle the call termination. - * If the call is oneOneOne on SFT, then delete MLS sub conversation - * otherwise leave the MLS conference. - * - * @param conversationId the conversation id. - * @param callProtocol the call protocol. - * @param conversationType the conversation type. - */ - suspend fun handleCallTermination( - conversationId: ConversationId, - conversationType: Conversation.Type? - ) } -class CallHelperImpl( - private val callRepository: CallRepository, - private val subconversationRepository: SubconversationRepository, - private val userConfigRepository: UserConfigRepository -) : CallHelper { +class CallHelperImpl : CallHelper { override fun shouldEndSFTOneOnOneCall( conversationId: ConversationId, @@ -94,36 +67,6 @@ class CallHelperImpl( } } - override suspend fun handleCallTermination( - conversationId: ConversationId, - conversationType: Conversation.Type? - ) { - if (userConfigRepository.shouldUseSFTForOneOnOneCalls().getOrElse(false) && - conversationType == Conversation.Type.ONE_ON_ONE - ) { - callingLogger.i("[CallHelper] -> fetching remote MLS sub conversation details") - subconversationRepository.fetchRemoteSubConversationDetails( - conversationId, - CALL_SUBCONVERSATION_ID - ).onSuccess { subconversationDetails -> - callingLogger.i("[CallHelper] -> Deleting remote MLS sub conversation") - subconversationRepository.deleteRemoteSubConversation( - subconversationDetails.parentId.toModel(), - SubconversationId(subconversationDetails.id), - SubconversationDeleteRequest( - subconversationDetails.epoch, - subconversationDetails.groupId - ) - ) - }.onFailure { - callingLogger.e("[CallHelper] -> Error fetching remote MLS sub conversation details") - } - } else { - callingLogger.i("[CallHelper] -> Leaving MLS conference") - callRepository.leaveMlsConference(conversationId) - } - } - companion object { const val TWO_PARTICIPANTS = 2 const val ONE_PARTICIPANTS = 1 diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt index e1e72b9a184..289e3a0593d 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/UserSessionScope.kt @@ -1236,7 +1236,6 @@ class UserSessionScope internal constructor( userRepository = userRepository, currentClientIdProvider = clientIdProvider, conversationRepository = conversationRepository, - subconversationRepository = subconversationRepository, userConfigRepository = userConfigRepository, selfConversationIdProvider = selfConversationIdProvider, messageSender = messages.messageSender, diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/call/GlobalCallManager.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/call/GlobalCallManager.kt index f306f6ea7f2..eb7bca57c8b 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/call/GlobalCallManager.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/call/GlobalCallManager.kt @@ -26,7 +26,6 @@ import com.wire.kalium.logic.data.call.mapper.CallMapper import com.wire.kalium.logic.data.call.CallRepository import com.wire.kalium.logic.data.call.VideoStateChecker import com.wire.kalium.logic.data.conversation.ConversationRepository -import com.wire.kalium.logic.data.conversation.SubconversationRepository import com.wire.kalium.logic.data.id.FederatedIdMapper import com.wire.kalium.logic.data.id.QualifiedID import com.wire.kalium.logic.data.id.QualifiedIdMapper @@ -49,7 +48,6 @@ expect class GlobalCallManager { currentClientIdProvider: CurrentClientIdProvider, selfConversationIdProvider: SelfConversationIdProvider, conversationRepository: ConversationRepository, - subconversationRepository: SubconversationRepository, userConfigRepository: UserConfigRepository, messageSender: MessageSender, callMapper: CallMapper, diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/CallHelperTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/CallHelperTest.kt index 6b515cd2d4d..945ee3eebad 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/CallHelperTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/data/call/CallHelperTest.kt @@ -17,27 +17,19 @@ */ package com.wire.kalium.logic.data.call -import com.wire.kalium.logic.NetworkFailure import com.wire.kalium.logic.StorageFailure import com.wire.kalium.logic.configuration.UserConfigRepository import com.wire.kalium.logic.data.conversation.Conversation -import com.wire.kalium.logic.data.conversation.SubconversationRepository import com.wire.kalium.logic.data.id.ConversationId import com.wire.kalium.logic.data.id.GroupID import com.wire.kalium.logic.data.id.QualifiedID import com.wire.kalium.logic.data.mls.CipherSuite import com.wire.kalium.logic.functional.Either -import com.wire.kalium.logic.test_util.TestNetworkException import com.wire.kalium.network.api.authenticated.conversation.SubconversationResponse import io.mockative.Mock -import io.mockative.any import io.mockative.classOf -import io.mockative.coEvery -import io.mockative.coVerify -import io.mockative.eq import io.mockative.every import io.mockative.mock -import io.mockative.once import kotlinx.coroutines.test.runTest import kotlinx.datetime.Instant import kotlin.test.Test @@ -116,89 +108,12 @@ class CallHelperTest { assertTrue { shouldEndSFTOneOnOneCall2 } } - @Test - fun givenMLSOneOnOneCallAndShouldUseSFTForOneOnOneCall_whenHandleCallTerminationIsCalled_thenDeleteRemoteSubConversation() = - runTest { - val (arrangement, mLSCallHelper) = Arrangement() - .withShouldUseSFTForOneOnOneCallsReturning(Either.Right(true)) - .withFetchRemoteSubConversationDetailsReturning( - Either.Right(subconversationResponse) - ) - .withDeleteRemoteSubConversationSuccess() - .arrange() - - mLSCallHelper.handleCallTermination(conversationId, Conversation.Type.ONE_ON_ONE) - - coVerify { - arrangement.subconversationRepository.deleteRemoteSubConversation(any(), any(), any()) - }.wasInvoked(exactly = once) - } - - @Test - fun givenSubconversationRepositoryReturnFailure_whenHandleCallTerminationIsCalled_thenDoNotDeleteRemoteSubConversation() = - runTest { - val (arrangement, mLSCallHelper) = Arrangement() - .withShouldUseSFTForOneOnOneCallsReturning(Either.Right(true)) - .withFetchRemoteSubConversationDetailsReturning( - Either.Left( - NetworkFailure.ServerMiscommunication( - TestNetworkException.badRequest - ) - ) - ) - .arrange() - - mLSCallHelper.handleCallTermination(conversationId, Conversation.Type.ONE_ON_ONE) - - coVerify { - arrangement.subconversationRepository.deleteRemoteSubConversation(any(), any(), any()) - }.wasNotInvoked() - } - - @Test - fun givenShouldNotUseSFTForOneOnOneCall_whenHandleCallTerminationIsCalled_thenLeaveMlsConference() = - runTest { - val (arrangement, mLSCallHelper) = Arrangement() - .withShouldUseSFTForOneOnOneCallsReturning(Either.Right(false)) - .arrange() - - mLSCallHelper.handleCallTermination(conversationId, Conversation.Type.GROUP) - - coVerify { - arrangement.callRepository.leaveMlsConference(any()) - }.wasInvoked(exactly = once) - } - - @Test - fun givenMLSGroupCall_whenHandleCallTerminationIsCalled_thenLeaveMlsConference() = - runTest { - val (arrangement, mLSCallHelper) = Arrangement() - .withShouldUseSFTForOneOnOneCallsReturning(Either.Right(true)) - .arrange() - - mLSCallHelper.handleCallTermination(conversationId, Conversation.Type.GROUP) - - coVerify { - arrangement.callRepository.leaveMlsConference(eq(conversationId)) - }.wasInvoked(exactly = once) - } - private class Arrangement { - @Mock - val callRepository = mock(classOf()) - - @Mock - val subconversationRepository = mock(classOf()) - @Mock val userConfigRepository = mock(classOf()) - private val mLSCallHelper: CallHelper = CallHelperImpl( - callRepository = callRepository, - subconversationRepository = subconversationRepository, - userConfigRepository = userConfigRepository - ) + private val mLSCallHelper: CallHelper = CallHelperImpl() fun arrange() = this to mLSCallHelper @@ -206,20 +121,6 @@ class CallHelperTest { apply { every { userConfigRepository.shouldUseSFTForOneOnOneCalls() }.returns(result) } - - suspend fun withFetchRemoteSubConversationDetailsReturning(result: Either) = - apply { - coEvery { - subconversationRepository.fetchRemoteSubConversationDetails(eq(conversationId), eq(CALL_SUBCONVERSATION_ID)) - }.returns(result) - } - - suspend fun withDeleteRemoteSubConversationSuccess() = - apply { - coEvery { - subconversationRepository.deleteRemoteSubConversation(any(), any(), any()) - }.returns(Either.Right(Unit)) - } } companion object { @@ -260,17 +161,5 @@ class CallHelperTest { id = QualifiedID("participantId2", "participantDomain2"), clientId = "efgh" ) - val subconversationResponse = SubconversationResponse( - id = "subconversationId", - parentId = com.wire.kalium.network.api.model.ConversationId( - "conversationId", - "domainId" - ), - groupId = "groupId", - epoch = 1UL, - epochTimestamp = "2021-03-30T15:36:00.000Z", - mlsCipherSuiteTag = 5, - members = listOf() - ) } } diff --git a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/call/scenario/OnCloseCallTest.kt b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/call/scenario/OnCloseCallTest.kt index aad607cd461..56fb0aec4e2 100644 --- a/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/call/scenario/OnCloseCallTest.kt +++ b/logic/src/jvmTest/kotlin/com/wire/kalium/logic/feature/call/scenario/OnCloseCallTest.kt @@ -34,8 +34,6 @@ import com.wire.kalium.logic.framework.TestUser import com.wire.kalium.network.NetworkState import com.wire.kalium.network.NetworkStateObserver import io.mockative.Mock -import io.mockative.any -import io.mockative.classOf import io.mockative.coVerify import io.mockative.eq import io.mockative.every @@ -57,9 +55,6 @@ class OnCloseCallTest { @Mock val networkStateObserver = mock(NetworkStateObserver::class) - @Mock - val callHelper = mock(classOf()) - val qualifiedIdMapper = QualifiedIdMapperImpl(TestUser.SELF.id) private lateinit var onCloseCall: OnCloseCall @@ -72,7 +67,6 @@ class OnCloseCallTest { fun setUp() { onCloseCall = OnCloseCall( callRepository, - callHelper, testScope, qualifiedIdMapper, networkStateObserver @@ -316,7 +310,7 @@ class OnCloseCallTest { }.wasInvoked(once) coVerify { - callHelper.handleCallTermination(eq(conversationId), any()) + callRepository.leaveMlsConference(eq(conversationId)) }.wasInvoked(once) }