Skip to content

Commit 727cccf

Browse files
gugaloDavDo
authored andcommitted
Fix chat back button listener race condition
There was a race condition where sometimes the old instance of ChatView was accessing and destroying the ChatController *after* a newer instance of ChatView had just set up the ChatController (same instance) causing the broken state of ChatController. MOB-3524
1 parent 69d2db6 commit 727cccf

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

widgetssdk/src/main/java/com/glia/widgets/chat/ChatContract.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ internal interface ChatContract {
2121
val isChatVisible: Boolean
2222

2323
fun setView(view: View)
24+
fun getView(): View?
2425
fun onDestroy(retain: Boolean)
2526
fun onMessageClicked(messageId: String)
2627
fun onGvaButtonClicked(button: GvaButton)

widgetssdk/src/main/java/com/glia/widgets/chat/ChatView.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,11 @@ internal class ChatView(context: Context, attrs: AttributeSet?, defStyleAttr: In
593593
}
594594

595595
private fun destroyController() {
596-
controller?.onDestroy(context.asActivity() is ChatActivity)
596+
controller?.let {
597+
if (it.getView() == this) {
598+
it.onDestroy(context.asActivity() is ChatActivity)
599+
}
600+
}
597601
controller = null
598602
}
599603

widgetssdk/src/main/java/com/glia/widgets/chat/controller/ChatController.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ internal class ChatController(
470470
view.scrollToBottomImmediate()
471471
}
472472

473+
@Synchronized
474+
override fun getView(): ChatContract.View? {
475+
return this.view
476+
}
477+
473478
override fun setOnBackClickedListener(finishCallback: ChatView.OnBackClickedListener?) {
474479
this.backClickedListener = finishCallback
475480
}

0 commit comments

Comments
 (0)