Skip to content

Commit

Permalink
Merge branch 'feat/create-password-protected-invite-code/epic' into f…
Browse files Browse the repository at this point in the history
…eat/use-case-for-is-a-user-can-create-password-protected-guest-links
  • Loading branch information
MohamadJaara authored Aug 5, 2023
2 parents 389be5c + c02db2a commit 50b235c
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ import com.wire.kalium.logic.feature.call.CallsScope
import com.wire.kalium.logic.feature.call.GlobalCallManager
import com.wire.kalium.logic.feature.call.usecase.ConversationClientsInCallUpdater
import com.wire.kalium.logic.feature.call.usecase.ConversationClientsInCallUpdaterImpl
import com.wire.kalium.logic.feature.call.usecase.UpdateConversationClientsForCurrentCallUseCase
import com.wire.kalium.logic.feature.call.usecase.UpdateConversationClientsForCurrentCallUseCaseImpl
import com.wire.kalium.logic.feature.client.ClientScope
import com.wire.kalium.logic.feature.client.IsAllowedToRegisterMLSClientUseCase
import com.wire.kalium.logic.feature.client.IsAllowedToRegisterMLSClientUseCaseImpl
Expand Down Expand Up @@ -970,6 +972,17 @@ class UserSessionScope internal constructor(
globalCallManager.getMediaManager()
}

private val conversationClientsInCallUpdater: ConversationClientsInCallUpdater
get() = ConversationClientsInCallUpdaterImpl(
callManager = callManager,
conversationRepository = conversationRepository,
federatedIdMapper = federatedIdMapper
)

private val updateConversationClientsForCurrentCall: Lazy<UpdateConversationClientsForCurrentCallUseCase> = lazy {
UpdateConversationClientsForCurrentCallUseCaseImpl(callRepository, conversationClientsInCallUpdater)
}

private val reactionRepository = ReactionRepositoryImpl(userId, userStorage.database.reactionDAO)
private val receiptRepository = ReceiptRepositoryImpl(userStorage.database.receiptDAO)
private val persistReaction: PersistReactionUseCase
Expand Down Expand Up @@ -1071,7 +1084,7 @@ class UserSessionScope internal constructor(
)
private val memberLeaveHandler: MemberLeaveEventHandler
get() = MemberLeaveEventHandlerImpl(
userStorage.database.memberDAO, userRepository, persistMessage
userStorage.database.memberDAO, userRepository, persistMessage, updateConversationClientsForCurrentCall
)
private val memberChangeHandler: MemberChangeEventHandler get() = MemberChangeEventHandlerImpl(conversationRepository)
private val mlsWelcomeHandler: MLSWelcomeEventHandler
Expand Down Expand Up @@ -1344,13 +1357,6 @@ class UserSessionScope internal constructor(
userConfigRepository, featureConfigRepository, getGuestRoomLinkFeature, kaliumConfigs, userId
)

val conversationClientsInCallUpdater: ConversationClientsInCallUpdater
get() = ConversationClientsInCallUpdaterImpl(
callManager = callManager,
conversationRepository = conversationRepository,
federatedIdMapper = federatedIdMapper
)

val team: TeamScope get() = TeamScope(userRepository, teamRepository, conversationRepository, selfTeamId)

val service: ServiceScope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ import com.wire.kalium.logic.feature.call.usecase.TurnLoudSpeakerOffUseCase
import com.wire.kalium.logic.feature.call.usecase.TurnLoudSpeakerOnUseCase
import com.wire.kalium.logic.feature.call.usecase.UnMuteCallUseCase
import com.wire.kalium.logic.feature.call.usecase.UnMuteCallUseCaseImpl
import com.wire.kalium.logic.feature.call.usecase.UpdateConversationClientsForCurrentCallUseCase
import com.wire.kalium.logic.feature.call.usecase.UpdateConversationClientsForCurrentCallUseCaseImpl
import com.wire.kalium.logic.feature.call.usecase.UpdateVideoStateUseCase
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import com.wire.kalium.logic.sync.SyncManager
Expand Down Expand Up @@ -124,8 +126,13 @@ class CallsScope internal constructor(
get() = EndCallOnConversationChangeUseCaseImpl(
callRepository = callRepository,
conversationRepository = conversationRepository,
endCallUseCase = endCall,
conversationClientsInCallUpdater = conversationClientsInCallUpdater
endCallUseCase = endCall
)

val updateConversationClientsForCurrentCallUseCase: UpdateConversationClientsForCurrentCallUseCase
get() = UpdateConversationClientsForCurrentCallUseCaseImpl(
callRepository,
conversationClientsInCallUpdater
)

val rejectCall: RejectCallUseCase get() = RejectCallUseCase(callManager, callRepository, KaliumDispatcherImpl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ interface EndCallOnConversationChangeUseCase {
class EndCallOnConversationChangeUseCaseImpl(
private val callRepository: CallRepository,
private val conversationRepository: ConversationRepository,
private val endCallUseCase: EndCallUseCase,
private val conversationClientsInCallUpdater: ConversationClientsInCallUpdater,
private val endCallUseCase: EndCallUseCase
) : EndCallOnConversationChangeUseCase {
override suspend operator fun invoke() {
val callsFlow = callRepository.establishedCallsFlow().map { calls ->
Expand All @@ -38,7 +37,6 @@ class EndCallOnConversationChangeUseCaseImpl(
if (it is ConversationDetails.Group) {
// Not a member anymore
if (!it.isSelfUserMember) {
conversationClientsInCallUpdater(calls.first())
endCallUseCase(calls.first())
}
} else if (it is ConversationDetails.OneOne) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.logic.feature.call.usecase

import com.wire.kalium.logic.data.call.CallRepository
import com.wire.kalium.logic.data.id.ConversationId
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map

/**
* This use case is responsible for updating conversation clients in a call
* Usually called when a member is removed from conversation
*/
interface UpdateConversationClientsForCurrentCallUseCase {
suspend operator fun invoke(conversationId: ConversationId)
}

internal class UpdateConversationClientsForCurrentCallUseCaseImpl(
private val callRepository: CallRepository,
private val conversationClientsInCallUpdater: ConversationClientsInCallUpdater
) : UpdateConversationClientsForCurrentCallUseCase {
override suspend fun invoke(conversationId: ConversationId) {
callRepository.establishedCallsFlow().map { calls -> calls.map { it.conversationId } }.first().find {
it == conversationId
}?.let {
conversationClientsInCallUpdater(conversationId)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.wire.kalium.logic.data.message.MessageContent
import com.wire.kalium.logic.data.message.PersistMessageUseCase
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.data.user.UserRepository
import com.wire.kalium.logic.feature.call.usecase.UpdateConversationClientsForCurrentCallUseCase
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.functional.flatMap
import com.wire.kalium.logic.functional.onFailure
Expand All @@ -45,6 +46,7 @@ internal class MemberLeaveEventHandlerImpl(
private val memberDAO: MemberDAO,
private val userRepository: UserRepository,
private val persistMessage: PersistMessageUseCase,
private val updateConversationClientsForCurrentCall: Lazy<UpdateConversationClientsForCurrentCallUseCase>,
) : MemberLeaveEventHandler {

override suspend fun handle(event: Event.Conversation.MemberLeave) =
Expand All @@ -55,6 +57,7 @@ internal class MemberLeaveEventHandlerImpl(
userRepository.fetchUsersIfUnknownByIds(event.removedList.toSet())
}
.onSuccess {
updateConversationClientsForCurrentCall.value(event.conversationId)
val message = Message.System(
id = event.id,
content = MessageContent.MemberChange.Removed(members = event.removedList),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,14 @@ class EndCallOnConversationChangeUseCaseTest {
@Mock
private val endCall = mock(classOf<EndCallUseCase>())

@Mock
private val conversationClientsInCallUpdater = mock(classOf<ConversationClientsInCallUpdater>())

private lateinit var endCallOnConversationChange: EndCallOnConversationChangeUseCase

@BeforeTest
fun setup() {
endCallOnConversationChange = EndCallOnConversationChangeUseCaseImpl(
callRepository = callRepository,
conversationRepository = conversationRepository,
endCallUseCase = endCall,
conversationClientsInCallUpdater = conversationClientsInCallUpdater
endCallUseCase = endCall
)

given(callRepository)
Expand Down Expand Up @@ -97,11 +93,6 @@ class EndCallOnConversationChangeUseCaseTest {

endCallOnConversationChange()

verify(conversationClientsInCallUpdater)
.suspendFunction(conversationClientsInCallUpdater::invoke)
.with(eq(conversationId))
.wasInvoked(once)

verify(endCall)
.suspendFunction(endCall::invoke)
.with(eq(conversationId))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/*
* Wire
* Copyright (C) 2023 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.kalium.logic.feature.call.usecase

import com.wire.kalium.logic.data.call.CallRepository
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.feature.call.Call
import com.wire.kalium.logic.feature.call.CallStatus
import io.mockative.Mock
import io.mockative.classOf
import io.mockative.eq
import io.mockative.given
import io.mockative.mock
import io.mockative.once
import io.mockative.verify
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import kotlin.test.BeforeTest
import kotlin.test.Test

class UpdateConversationClientsForCurrentCallUseCaseTest {

@Mock
private val callRepository = mock(classOf<CallRepository>())

@Mock
private val conversationClientsInCallUpdater = mock(classOf<ConversationClientsInCallUpdater>())

private lateinit var updateConversationClientsForCurrentCall: UpdateConversationClientsForCurrentCallUseCase

@BeforeTest
fun setup() {
updateConversationClientsForCurrentCall = UpdateConversationClientsForCurrentCallUseCaseImpl(
callRepository = callRepository,
conversationClientsInCallUpdater = conversationClientsInCallUpdater
)
}

@Test
fun givenNoOngoingCall_whenUseCaseIsInvoked_thenNothingToDo() = runTest {
given(callRepository)
.suspendFunction(callRepository::establishedCallsFlow)
.whenInvoked()
.thenReturn(flowOf(listOf()))

updateConversationClientsForCurrentCall(CONVERSATION_ID)

verify(callRepository)
.suspendFunction(callRepository::establishedCallsFlow)
.wasInvoked(once)

verify(conversationClientsInCallUpdater)
.suspendFunction(conversationClientsInCallUpdater::invoke)
.with(eq(CONVERSATION_ID))
.wasNotInvoked()
}

@Test
fun givenAnOngoingCall_whenUseCaseIsInvoked_thenUpdateClients() = runTest {
given(callRepository)
.suspendFunction(callRepository::establishedCallsFlow)
.whenInvoked()
.thenReturn(flowOf(listOf(call)))

updateConversationClientsForCurrentCall(CONVERSATION_ID)

verify(callRepository)
.suspendFunction(callRepository::establishedCallsFlow)
.wasInvoked(once)
verify(conversationClientsInCallUpdater)
.suspendFunction(conversationClientsInCallUpdater::invoke)
.with(eq(CONVERSATION_ID))
.wasInvoked()
}

companion object {
private val CONVERSATION_ID = ConversationId("conversationId", "domain")
private val call = Call(
conversationId = CONVERSATION_ID,
status = CallStatus.ESTABLISHED,
callerId = "called-id",
isMuted = false,
isCameraOn = false,
isCbrEnabled = false,
conversationName = null,
conversationType = Conversation.Type.GROUP,
callerName = null,
callerTeamName = null,
establishedTime = null
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,9 @@ import io.mockative.matching
import io.mockative.mock
import io.mockative.once
import io.mockative.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import kotlin.test.Test

@OptIn(ExperimentalCoroutinesApi::class)
class MemberJoinEventHandlerTest {

@Test
Expand Down
Loading

0 comments on commit 50b235c

Please sign in to comment.