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

Do not cancel queue ticket if visitor selects engagement of the same type during queueing #1207

Open
wants to merge 1 commit into
base: feature/mob-3003-remove-deprecated-functions
Choose a base branch
from
Open
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 @@ -424,7 +424,8 @@ internal class ChatManager(
fun mapInQueue(state: State): State = state.apply {
OperatorStatusItem.InQueue.also {
operatorStatusItem = it
chatItems += it
val isQueueingItemAlreadyDisplayed = chatItems.size > 0 && chatItems[chatItems.lastIndex] == it
if (!isQueueingItemAlreadyDisplayed) chatItems += it
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ internal interface EngagementRepository {
val isTransferredSecureConversation: Boolean
val isQueueing: Boolean
val isQueueingForMedia: Boolean
val isQueueingForVideo: Boolean
val isQueueingForAudio: Boolean
val isCallVisualizerEngagement: Boolean
val isOperatorPresent: Boolean
val isSharingScreen: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ internal class EngagementRepositoryImpl(
override val isQueueingForMedia: Boolean
get() = currentState?.queueingMediaType?.isAudioOrVideo() == true

override val isQueueingForAudio: Boolean
get() = (currentState?.queueingMediaType == MediaType.AUDIO)

override val isQueueingForVideo: Boolean
get() = (currentState?.queueingMediaType == MediaType.VIDEO)

override val isCallVisualizerEngagement: Boolean
get() = currentEngagement is OmnibrowseEngagement

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.glia.widgets.engagement.EngagementRepository
internal interface IsQueueingOrLiveEngagementUseCase {
val hasOngoingLiveEngagement: Boolean
val isQueueingForMedia: Boolean
val isQueueingForAudio: Boolean
val isQueueingForVideo: Boolean
val isQueueingForLiveChat: Boolean
val isQueueing: Boolean
operator fun invoke(): Boolean
Expand All @@ -13,6 +15,8 @@ internal interface IsQueueingOrLiveEngagementUseCase {
internal class IsQueueingOrLiveEngagementUseCaseImpl(private val engagementRepository: EngagementRepository) : IsQueueingOrLiveEngagementUseCase {
override val hasOngoingLiveEngagement: Boolean get() = engagementRepository.hasOngoingLiveEngagement
override val isQueueingForMedia: Boolean get() = engagementRepository.isQueueingForMedia
override val isQueueingForAudio: Boolean get() = engagementRepository.isQueueingForAudio
override val isQueueingForVideo: Boolean get() = engagementRepository.isQueueingForVideo
override val isQueueingForLiveChat: Boolean get() = engagementRepository.isQueueing && !isQueueingForMedia
override val isQueueing: Boolean get() = engagementRepository.isQueueing
override fun invoke(): Boolean = engagementRepository.isQueueingOrLiveEngagement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ internal class EngagementLauncherImpl(
) : EngagementLauncher {

override fun startChat(context: Context, visitorContextAssetId: String?) {
if (isQueueingOrLiveEngagementUseCase.isQueueing) {
if (isQueueingOrLiveEngagementUseCase.isQueueingForMedia) {
Logger.i(TAG, "Canceling ongoing queue ticket to create a new one")
endEngagementUseCase()
controllerFactory.destroyChatController()
Expand All @@ -75,7 +75,7 @@ internal class EngagementLauncherImpl(
}

override fun startAudioCall(context: Context, visitorContextAssetId: String?) {
if (isQueueingOrLiveEngagementUseCase.isQueueing) {
if (isQueueingOrLiveEngagementUseCase.isQueueingForLiveChat || isQueueingOrLiveEngagementUseCase.isQueueingForVideo) {
Logger.i(TAG, "Canceling ongoing queue ticket to create a new one")
endEngagementUseCase()
controllerFactory.destroyCallController()
Expand All @@ -92,7 +92,7 @@ internal class EngagementLauncherImpl(
}

override fun startVideoCall(context: Context, visitorContextAssetId: String?) {
if (isQueueingOrLiveEngagementUseCase.isQueueing) {
if (isQueueingOrLiveEngagementUseCase.isQueueingForLiveChat || isQueueingOrLiveEngagementUseCase.isQueueingForAudio) {
Logger.i(TAG, "Canceling ongoing queue ticket to create a new one")
endEngagementUseCase()
controllerFactory.destroyCallController()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.glia.widgets.core.secureconversations.domain.HasOngoingSecureConversa
import com.glia.widgets.di.ControllerFactory
import com.glia.widgets.engagement.domain.EndEngagementUseCase
import com.glia.widgets.engagement.domain.IsQueueingOrLiveEngagementUseCase
import com.glia.widgets.helper.Logger
import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.MockK
Expand Down Expand Up @@ -45,6 +46,7 @@ class EngagementLauncherImplTest {
@Before
fun setUp() {
MockKAnnotations.init(this)
Logger.setIsDebug(false)
engagementLauncher = EngagementLauncherImpl(
activityLauncher,
hasOngoingSecureConversationUseCase,
Expand All @@ -58,7 +60,7 @@ class EngagementLauncherImplTest {
@Test
fun `startChat launches live chat when no pending secure conversations`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false
mockNoQueueing()

engagementLauncher.startChat(activity)

Expand All @@ -69,7 +71,7 @@ class EngagementLauncherImplTest {
@Test
fun `startChat launches secure conversation dialog when there are pending secure conversations`() {
mockOngoingInteractionCallback(true)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false
mockNoQueueing()

engagementLauncher.startChat(activity, visitorContextAssetId)

Expand All @@ -80,7 +82,7 @@ class EngagementLauncherImplTest {
@Test
fun `startAudioCall launches audio call when no pending secure conversations`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false
mockNoQueueing()

engagementLauncher.startAudioCall(activity)

Expand All @@ -91,7 +93,7 @@ class EngagementLauncherImplTest {
@Test
fun `startAudioCall launches secure conversation audio dialog when there are pending secure conversations`() {
mockOngoingInteractionCallback(true)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false
mockNoQueueing()

engagementLauncher.startAudioCall(activity, visitorContextAssetId)

Expand All @@ -102,7 +104,7 @@ class EngagementLauncherImplTest {
@Test
fun `startVideoCall launches video call when no pending secure conversations`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false
mockNoQueueing()

engagementLauncher.startVideoCall(activity)

Expand All @@ -113,7 +115,7 @@ class EngagementLauncherImplTest {
@Test
fun `startVideoCall launches secure conversation video dialog when there are pending secure conversations`() {
mockOngoingInteractionCallback(true)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false
mockNoQueueing()

engagementLauncher.startVideoCall(activity, visitorContextAssetId)

Expand All @@ -124,7 +126,7 @@ class EngagementLauncherImplTest {
@Test
fun `startSecureMessaging launches secure messaging welcome screen when no pending secure conversations`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false
mockNoQueueing()

engagementLauncher.startSecureMessaging(activity)

Expand All @@ -135,7 +137,7 @@ class EngagementLauncherImplTest {
@Test
fun `startSecureMessaging launches secure chat when there are pending secure conversations`() {
mockOngoingInteractionCallback(true)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns false
mockNoQueueing()

engagementLauncher.startSecureMessaging(activity, visitorContextAssetId)

Expand All @@ -149,10 +151,17 @@ class EngagementLauncherImplTest {
}
}

private fun mockNoQueueing() {
every { isQueueingOrLiveEngagementUseCase.isQueueingForMedia } returns false
every { isQueueingOrLiveEngagementUseCase.isQueueingForVideo } returns false
every { isQueueingOrLiveEngagementUseCase.isQueueingForAudio } returns false
every { isQueueingOrLiveEngagementUseCase.isQueueingForLiveChat } returns false
}

@Test
fun `startChat ends engagement and destroys chat controller when queueing`() {
fun `startChat ends engagement and destroys chat controller when queueing for media`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns true
every { isQueueingOrLiveEngagementUseCase.isQueueingForMedia } returns true

engagementLauncher.startChat(activity)

Expand All @@ -162,9 +171,22 @@ class EngagementLauncherImplTest {
}

@Test
fun `startAudioCall ends engagement and destroys call controller when queueing`() {
fun `startChat does not end engagement and does not destroy chat controller when queueing for chat`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueingForMedia } returns false

engagementLauncher.startChat(activity)

verify(exactly = 0) { endEngagementUseCase() }
verify(exactly = 0) { controllerFactory.destroyChatController() }
verify { activityLauncher.launchChat(activity, Intention.LIVE_CHAT) }
}

@Test
fun `startAudioCall ends engagement and destroys call controller when queueing for chat`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns true
every { isQueueingOrLiveEngagementUseCase.isQueueingForLiveChat } returns true
every { isQueueingOrLiveEngagementUseCase.isQueueingForVideo } returns false

engagementLauncher.startAudioCall(activity)

Expand All @@ -174,14 +196,67 @@ class EngagementLauncherImplTest {
}

@Test
fun `startVideoCall ends engagement and destroys call controller when queueing`() {
fun `startAudioCall ends engagement and destroys call controller when queueing for video`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueingForLiveChat } returns false
every { isQueueingOrLiveEngagementUseCase.isQueueingForVideo } returns true

engagementLauncher.startAudioCall(activity)

verify { endEngagementUseCase() }
verify { controllerFactory.destroyCallController() }
verify { activityLauncher.launchCall(activity, Engagement.MediaType.AUDIO, false) }
}

@Test
fun `startAudioCall does not end engagement and does not destroy call controller when queueing for audio`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueingForLiveChat } returns false
every { isQueueingOrLiveEngagementUseCase.isQueueingForVideo } returns false

engagementLauncher.startAudioCall(activity)

verify(exactly = 0) { endEngagementUseCase() }
verify(exactly = 0) { controllerFactory.destroyCallController() }
verify { activityLauncher.launchCall(activity, Engagement.MediaType.AUDIO, false) }
}

@Test
fun `startVideoCall ends engagement and destroys call controller when queueing for chat`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueing } returns true
every { isQueueingOrLiveEngagementUseCase.isQueueingForLiveChat } returns true
every { isQueueingOrLiveEngagementUseCase.isQueueingForAudio } returns false

engagementLauncher.startVideoCall(activity)

verify { endEngagementUseCase() }
verify { controllerFactory.destroyCallController() }
verify { activityLauncher.launchCall(activity, Engagement.MediaType.VIDEO, false) }
}

@Test
fun `startVideoCall ends engagement and destroys call controller when queueing for audio`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueingForLiveChat } returns false
every { isQueueingOrLiveEngagementUseCase.isQueueingForAudio } returns true

engagementLauncher.startVideoCall(activity)

verify { endEngagementUseCase() }
verify { controllerFactory.destroyCallController() }
verify { activityLauncher.launchCall(activity, Engagement.MediaType.VIDEO, false) }
}

@Test
fun `startVideoCall does not end engagement and does not destroy call controller when queueing for video`() {
mockOngoingInteractionCallback(false)
every { isQueueingOrLiveEngagementUseCase.isQueueingForLiveChat } returns false
every { isQueueingOrLiveEngagementUseCase.isQueueingForAudio } returns false

engagementLauncher.startVideoCall(activity)

verify(exactly = 0) { endEngagementUseCase() }
verify(exactly = 0) { controllerFactory.destroyCallController() }
verify { activityLauncher.launchCall(activity, Engagement.MediaType.VIDEO, false) }
}
}