Skip to content

Commit

Permalink
Fix chat back button listener race condition
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gugalo committed Sep 10, 2024
1 parent 405b9f4 commit 2c56d8b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal interface ChatContract {
val isChatVisible: Boolean

fun setView(view: View)
fun getView(): View?
fun onDestroy(retain: Boolean)
fun onMessageClicked(messageId: String)
fun onGvaButtonClicked(button: GvaButton)
Expand Down
6 changes: 5 additions & 1 deletion widgetssdk/src/main/java/com/glia/widgets/chat/ChatView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,11 @@ internal class ChatView(context: Context, attrs: AttributeSet?, defStyleAttr: In
}

private fun destroyController() {
controller?.onDestroy(context.asActivity() is ChatActivity)
controller?.let {
if (it.getView() == this) {
it.onDestroy(context.asActivity() is ChatActivity)
}
}
controller = null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ internal class ChatController(
view.scrollToBottomImmediate()
}

@Synchronized
override fun getView(): ChatContract.View? {
return this.view
}

override fun setOnBackClickedListener(finishCallback: ChatView.OnBackClickedListener?) {
this.backClickedListener = finishCallback
}
Expand Down

0 comments on commit 2c56d8b

Please sign in to comment.