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

Implement EngagementLauncher business logic for ongoing live engagement #1206

Open
wants to merge 1 commit into
base: feature/entry-widget-and-secure-conversations-v2
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ allprojects {
// Needed for some automated and manual testing (e.g: acceptance tests)
mavenLocal()
//TODO switch to the release version before releasing core SDK
maven { url = "https://s01.oss.sonatype.org/content/repositories/comglia-1339" }
maven { url = "https://s01.oss.sonatype.org/content/repositories/comglia-1340" }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.glia.widgets.callvisualizer

import android.app.Activity
import androidx.annotation.StringRes
import com.glia.widgets.R
import com.glia.widgets.base.BaseSingleActivityWatcher
import com.glia.widgets.callvisualizer.controller.CallVisualizerContract
Expand All @@ -14,7 +15,6 @@ import com.glia.widgets.launcher.ActivityLauncher
import com.glia.widgets.locale.LocaleProvider
import com.glia.widgets.locale.LocaleString
import com.glia.widgets.view.Dialogs
import com.glia.widgets.view.snackbar.SnackBarDelegate
import com.glia.widgets.view.snackbar.SnackBarDelegateFactory
import com.glia.widgets.view.unifiedui.theme.UnifiedThemeManager
import com.glia.widgets.webbrowser.WebBrowserActivity
Expand Down Expand Up @@ -45,7 +45,8 @@ internal class CallVisualizerActivityWatcher(
activity == null || activity.isFinishing -> Logger.d(TAG, "skipping.. activity is null or finishing")
activity is WebBrowserActivity && state is ControllerState.DisplayConfirmationDialog -> Logger.d(TAG, "skipping.. WebBrowser is open")
activity is WebBrowserActivity && state is ControllerState.OpenWebBrowserScreen -> event.consume { controller.onWebBrowserOpened() }
state is ControllerState.ShowTimeoutSnackBar -> event.consume { showSnackBar(activity) }
state is ControllerState.ShowTimeoutSnackBar -> event.consume { showTimedOutSnackBar(activity) }
state is ControllerState.ShowAlreadyInCallSnackBar -> event.consume { showAlreadyInCallSnackBar(activity) }
//Ensure this state remains unconsumed until the opening of the WebBrowserActivity.
state is ControllerState.OpenWebBrowserScreen -> openWebBrowser(activity, state.title, state.url)
state is ControllerState.DisplayVisitorCodeDialog -> displayVisitorCodeDialog(activity)
Expand Down Expand Up @@ -94,15 +95,15 @@ internal class CallVisualizerActivityWatcher(
activityLauncher.launchWebBrowser(activity, title, url)
}

private fun showSnackBar(activity: Activity) {
makeSnackBar(activity).show()
}
private fun showTimedOutSnackBar(activity: Activity) = showSnackBar(activity, R.string.engagement_incoming_request_timed_out_message)

private fun showAlreadyInCallSnackBar(activity: Activity) = showSnackBar(activity, R.string.entry_widget_call_visualizer_description)

private fun showSnackBar(activity: Activity, @StringRes messageRes: Int) = SnackBarDelegateFactory(
activity,
messageRes,
localeProvider,
themeManager.theme
).createDelegate().show()

private fun makeSnackBar(activity: Activity): SnackBarDelegate =
SnackBarDelegateFactory(
activity,
R.string.engagement_incoming_request_timed_out_message,
localeProvider,
themeManager.theme
).createDelegate()
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ import com.glia.widgets.engagement.State as EngagementState
internal interface CallVisualizerContract {

sealed interface State {
object DisplayVisitorCodeDialog : State
data object DisplayVisitorCodeDialog : State
data class DisplayConfirmationDialog(val links: ConfirmationDialogLinks) : State
object DismissDialog : State
object ShowTimeoutSnackBar : State
object CloseHolderActivity : State
data object DismissDialog : State
data object ShowTimeoutSnackBar : State
data object ShowAlreadyInCallSnackBar : State
data object CloseHolderActivity : State
data class OpenWebBrowserScreen(val title: LocaleString, val url: String) : State
}

Expand All @@ -43,6 +44,7 @@ internal interface CallVisualizerContract {
fun onLinkClicked(link: Link)
fun dismissVisitorCodeDialog()
fun onWebBrowserOpened()
fun showAlreadyInCallSnackBar()
}
}

Expand Down Expand Up @@ -142,6 +144,10 @@ internal class CallVisualizerController(
dialogController.showCVEngagementConfirmationDialog()
}

override fun showAlreadyInCallSnackBar() {
_state.onNext(CallVisualizerContract.State.ShowAlreadyInCallSnackBar)
}

private fun closeHolderActivity() {
_state.onNext(CallVisualizerContract.State.CloseHolderActivity)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.glia.widgets.core.secureconversations.domain

import com.glia.widgets.chat.domain.IsAuthenticatedUseCase
import com.glia.widgets.core.secureconversations.SecureConversationsRepository
import com.glia.widgets.engagement.State
import com.glia.widgets.engagement.domain.EngagementStateUseCase
Expand All @@ -10,7 +9,6 @@ import io.reactivex.rxjava3.core.Flowable

internal class HasOngoingSecureConversationUseCase(
private val secureConversationsRepository: SecureConversationsRepository,
private val isAuthenticatedUseCase: IsAuthenticatedUseCase,
private val engagementStateUseCase: EngagementStateUseCase
) {
/**
Expand All @@ -22,12 +20,19 @@ internal class HasOngoingSecureConversationUseCase(
secureConversationsRepository.unreadMessagesCountObservable,
engagementStateUseCase()
) { pendingSecureConversations, unreadMessagesCount, state ->
isAuthenticatedUseCase() &&
(pendingSecureConversations || unreadMessagesCount > 0 || state is State.TransferredToSecureConversation)
pendingSecureConversations || unreadMessagesCount > 0 || state is State.TransferredToSecureConversation
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the isAuthenticatedUseCase() check, as it was included in the unread_messages_count observable on the core SDK side.

}

operator fun invoke(): Flowable<Boolean> = hasOngoingInteraction.distinctUntilChanged().observeOn(AndroidSchedulers.mainThread())

operator fun invoke(callback: (Boolean) -> Unit) = invoke().firstOrError().unSafeSubscribe(callback)
operator fun invoke(onHasOngoingSecureConversation: () -> Unit, onNoOngoingSecureConversation: () -> Unit) {
invoke().firstOrError().unSafeSubscribe { hasOngoing ->
if (hasOngoing) {
onHasOngoingSecureConversation()
} else {
onNoOngoingSecureConversation()
}
}
}

}
16 changes: 10 additions & 6 deletions widgetssdk/src/main/java/com/glia/widgets/di/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ internal object Dependencies {
@JvmStatic
val engagementLauncher: EngagementLauncher by lazy {
EngagementLauncherImpl(
activityLauncher,
useCaseFactory.hasPendingSecureConversationsWithTimeoutUseCase,
useCaseFactory.isQueueingOrEngagementUseCase,
useCaseFactory.endEngagementUseCase,
configurationManager,
controllerFactory)
activityLauncher = activityLauncher,
hasOngoingSecureConversationUseCase = useCaseFactory.hasPendingSecureConversationsWithTimeoutUseCase,
isQueueingOrLiveEngagementUseCase = useCaseFactory.isQueueingOrEngagementUseCase,
endEngagementUseCase = useCaseFactory.endEngagementUseCase,
configurationManager = configurationManager,
engagementTypeUseCase = useCaseFactory.engagementTypeUseCase,
callVisualizerController = controllerFactory.callVisualizerController,
destroyChatController = controllerFactory::destroyChatController,
destroyCallController = controllerFactory::destroyCallController
)
}

@JvmStatic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,6 @@ public FlipCameraButtonStateUseCase getFlipCameraButtonStateUseCase() {
public HasOngoingSecureConversationUseCase getHasPendingSecureConversationsWithTimeoutUseCase() {
return new HasOngoingSecureConversationUseCase(
repositoryFactory.getSecureConversationsRepository(),
createIsAuthenticatedUseCase(),
getEngagementStateUseCase()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal interface EngagementTypeUseCase {
val isChatEngagement: Boolean
val isCallVisualizer: Boolean
val isCallVisualizerScreenSharing: Boolean
val hasVideo: Boolean

operator fun invoke(): Flowable<MediaType>
}
Expand All @@ -26,7 +27,7 @@ internal class EngagementTypeUseCaseImpl(
) : EngagementTypeUseCase {
private val hasOngoingEngagement get() = isQueueingOrLiveEngagementUseCase.hasOngoingLiveEngagement
private val hasAudio: Boolean get() = visitorMediaUseCase.hasAudio || operatorMediaUseCase.hasAudio
private val hasVideo: Boolean get() = visitorMediaUseCase.hasVideo || operatorMediaUseCase.hasVideo
override val hasVideo: Boolean get() = visitorMediaUseCase.hasVideo || operatorMediaUseCase.hasVideo
override val isAudioEngagement: Boolean get() = hasOngoingEngagement && isOperatorPresentUseCase() && hasAudio
override val isVideoEngagement: Boolean get() = hasOngoingEngagement && isOperatorPresentUseCase() && hasVideo
private val hasAnyMedia: Boolean get() = visitorMediaUseCase.hasMedia || operatorMediaUseCase.hasMedia
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,16 @@ internal class EntryWidgetImpl(
) : EntryWidget {

override fun show(activity: Activity) {
hasOngoingSecureConversationUseCase {
handleShowWithPendingSecureConversations(it, activity)
}
}

private fun handleShowWithPendingSecureConversations(hasPendingSecureConversations: Boolean, activity: Activity) {
if (hasPendingSecureConversations) {
activityLauncher.launchChat(activity, Intention.SC_CHAT)
} else {
activityLauncher.launchEntryWidget(activity)
}
hasOngoingSecureConversationUseCase(
onHasOngoingSecureConversation = { activityLauncher.launchChat(activity, Intention.SC_CHAT) },
onNoOngoingSecureConversation = { activityLauncher.launchEntryWidget(activity) }
)
}

override fun getView(context: Context): View {
val entryWidgetTheme = themeManager.theme?.entryWidgetTheme
val adapter = EntryWidgetAdapter(
EntryWidgetContract.ViewType.EMBEDDED_VIEW,
entryWidgetTheme
)
val adapter = EntryWidgetAdapter(EntryWidgetContract.ViewType.EMBEDDED_VIEW, entryWidgetTheme)

//Wrapping with Glia theme to make the Theme available for embedded view
return EntryWidgetView(context.wrapWithTheme()).apply {
setAdapter(adapter)
Expand Down
Loading