Skip to content

Commit

Permalink
Fix engagement started on the chat screen
Browse files Browse the repository at this point in the history
When the chat screen opens with the secure conversation state, resubscribe to the engagement streams. This solves the upgrade to chat state issue.

MOB-3888
  • Loading branch information
AH-MOC committed Dec 20, 2024
1 parent 360bb87 commit 0eb5075
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ internal class ChatController(

private val disposable = CompositeDisposable()
private val mediaUpgradeDisposable = CompositeDisposable()
private val engagementDisposable = CompositeDisposable()

private val sendMessageCallback: GliaSendMessageUseCase.Listener = object : GliaSendMessageUseCase.Listener {
override fun messageSent(message: VisitorMessage?) {
Expand Down Expand Up @@ -258,6 +259,10 @@ internal class ChatController(
emitViewState { chatState.initChat().setSecureMessagingState() }
ensureSecureMessagingAvailable()
observeTopBannerUseCase()

// When the chat screen opens with the secure conversation state, resubscribe to the engagement streams.
// This solves the upgrade to chat state issue.
subscribeToEngagement()
}

private fun observeTopBannerUseCase() {
Expand Down Expand Up @@ -287,9 +292,10 @@ internal class ChatController(
}

private fun subscribeToEngagement() {
engagementStateUseCase().unSafeSubscribe(::onEngagementStateChanged)
operatorMediaUseCase().unSafeSubscribe(::onNewOperatorMediaState)
onOperatorTypingUseCase().unSafeSubscribe(::onOperatorTyping)
engagementDisposable.clear()
engagementDisposable.add(engagementStateUseCase().subscribe(::onEngagementStateChanged))
engagementDisposable.add(operatorMediaUseCase().subscribe(::onNewOperatorMediaState))
engagementDisposable.add(onOperatorTypingUseCase().subscribe(::onOperatorTyping))
}

private fun ensureSecureMessagingAvailable() {
Expand Down Expand Up @@ -376,6 +382,7 @@ internal class ChatController(
backClickedListener = null
if (!retain) {
disposable.clear()
engagementDisposable.clear()
timerStatusListener = null
callTimer.clear()
minimizeHandler.clear()
Expand Down

0 comments on commit 0eb5075

Please sign in to comment.