TP-54713 | Girish Suragani | Fixed typing cues and scroll issue in ch… (#9404)

This commit is contained in:
Girish Suragani
2024-01-18 10:48:49 +05:30
committed by GitHub
parent b65118172e
commit 974d249a81
4 changed files with 23 additions and 12 deletions

View File

@@ -10,5 +10,6 @@ package com.navi.chat.models
data class ChatConfigConstructedResponse(
val fileSizeInKB: HashMap<String, Int>? = null,
val botTypingCuesDelayInMs: Long? = null,
val genAiTypingCuesDelayInMs: Long? = null,
val csatAppearanceDelayInMs: Long? = null
)

View File

@@ -12,7 +12,8 @@ import com.google.gson.annotations.SerializedName
data class ChatConfigResponse(
@SerializedName("fileUpload") val fileUpload: FileUpload? = null,
@SerializedName("botTypingCuesDelayInMs") val botTypingCuesDelayInMs: Int? = null,
@SerializedName("csatAppearanceDelayInMs") val chatAppearanceDelayInMs: Int? = null,
@SerializedName("genAiTypingCuesDelayInMs") val genAiTypingCuesDelayInMs: Int? = null,
@SerializedName("csatAppearanceDelayInMs") val chatAppearanceDelayInMs: Int? = null
)
data class FileUpload(

View File

@@ -120,6 +120,7 @@ class NaviChatFragment : ChatBaseFragment(), WidgetCallback, MessageOperation, T
private var shouldHideLoader: Boolean? = false
private var shouldShowChatResolutionWidget: Boolean = false
private var delayForTypingCuesForBot = 1000L
private var delayForTypingCuesForGenAi = 300000L
private var delayForShowingCsat = 2000L
private var conversationId: String? = null
private var inactivityTimer: Runnable? = null
@@ -340,6 +341,10 @@ class NaviChatFragment : ChatBaseFragment(), WidgetCallback, MessageOperation, T
delayForTypingCuesForBot = botDelayInMs
Timber.d("Updated delayForTypingCuesForBot to $botDelayInMs")
}
it.genAiTypingCuesDelayInMs?.let { genAiDelayInMs ->
delayForTypingCuesForGenAi = genAiDelayInMs
Timber.d("Updated genAiTypingCuesDelayInMs to $genAiDelayInMs")
}
it.csatAppearanceDelayInMs?.let { csatDelayInMs ->
delayForShowingCsat = csatDelayInMs
}
@@ -965,7 +970,7 @@ class NaviChatFragment : ChatBaseFragment(), WidgetCallback, MessageOperation, T
private fun isValidTimeStamp(updatedAt: Timestamp?): Boolean {
updatedAt?.let {
val milliseconds = updatedAt.seconds * 1000 + updatedAt.nanoseconds / 1000000
if (System.currentTimeMillis() - milliseconds <= DELAY_TO_HIDE_TYPING) {
if (System.currentTimeMillis() - milliseconds <= delayForTypingCuesForGenAi) {
return true
}
}
@@ -994,7 +999,7 @@ class NaviChatFragment : ChatBaseFragment(), WidgetCallback, MessageOperation, T
scrollChatToLatestMessageReceived()
}
},
DELAY_TO_HIDE_TYPING
delayForTypingCuesForGenAi
)
} else {
typingStatusHandler.removeCallbacksAndMessages(null)
@@ -1103,14 +1108,14 @@ class NaviChatFragment : ChatBaseFragment(), WidgetCallback, MessageOperation, T
chatRVAdapter.list.isNotEmpty() &&
chatRVAdapter.list[0] is NaviChatTypingStatusWidget
) {
insertItemAtIndexAndSetTimeStamp(1, widgetModel)
insertItemAtIndexAndSetTimeStamp(1, widgetModel, true)
} else {
insertItemAtIndexAndSetTimeStamp(0, widgetModel)
}
}
}
private fun insertItemAtIndexAndSetTimeStamp(index: Int, widgetModel: NaviChatWidget) {
private fun insertItemAtIndexAndSetTimeStamp(index: Int, widgetModel: NaviChatWidget, scrollWithoutDelay: Boolean? = false) {
if (naviChatViewModel.latestMessageTimeStamp != null) {
if (!naviChatViewModel.getDividerShown() && !isDateSameWithCurrentDay(
naviChatViewModel.latestMessageTimeStamp
@@ -1121,7 +1126,7 @@ class NaviChatFragment : ChatBaseFragment(), WidgetCallback, MessageOperation, T
}
}
chatRVAdapter.insertNewItemAtIndex(index, widgetModel)
scrollChatToLatestMessageReceived()
scrollChatToLatestMessageReceived(scrollWithoutDelay)
naviChatViewModel.setLatestMessageLatestTimeStamp(widgetModel.rt_created_at)
}
@@ -1546,12 +1551,16 @@ class NaviChatFragment : ChatBaseFragment(), WidgetCallback, MessageOperation, T
}
}
fun scrollChatToLatestMessageReceived() {
fun scrollChatToLatestMessageReceived(scrollWithoutDelay: Boolean? = false) {
if (view != null) {
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
delay(DELAY_TO_SCROLL)
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
binding.rvChat.smoothScrollToPosition(0)
if (scrollWithoutDelay == true) {
binding.rvChat.smoothScrollToPosition(0)
} else {
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
delay(DELAY_TO_SCROLL)
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.Main) {
binding.rvChat.smoothScrollToPosition(0)
}
}
}
}
@@ -1627,7 +1636,6 @@ class NaviChatFragment : ChatBaseFragment(), WidgetCallback, MessageOperation, T
companion object {
const val TAG = "NaviChatFragment"
private const val DELAY_TO_SCROLL = 200L
private const val DELAY_TO_HIDE_TYPING = 10000L
private const val MARGIN_TO_RIGHT = 16
private const val ANIMATION_DURATION = 400L
}

View File

@@ -291,6 +291,7 @@ constructor(private val naviChatRepository: NaviChatRepository, private val cont
return ChatConfigConstructedResponse(
fileSizeInKB = getHashMap(response),
botTypingCuesDelayInMs = response.botTypingCuesDelayInMs?.toLong() ?: 1000L,
genAiTypingCuesDelayInMs = response.genAiTypingCuesDelayInMs?.toLong() ?: 300000L,
csatAppearanceDelayInMs = response.chatAppearanceDelayInMs?.toLong() ?: 2000L
)
}