From 82abb9d9bdb8808ed33784a64f998f04c31d1c02 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 7 Mar 2023 15:49:23 +0100 Subject: [PATCH] Fix to avoid duplicated messages for HTTP_CODE_NOT_MODIFIED the "historyRead" didn't make any sense to me, and deleting it solved the issue to avoid duplicated messages when the response was HTTP_CODE_NOT_MODIFIED Signed-off-by: Marcel Hibbe --- .../talk/controllers/ChatController.kt | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt index 0ccc90639..67c03be64 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt @@ -257,7 +257,6 @@ class ChatController(args: Bundle) : private val roomPassword: String var credentials: String? = null var currentConversation: Conversation? = null - private var historyRead = false private var globalLastKnownFutureMessageId = -1 private var globalLastKnownPastMessageId = -1 var adapter: TalkMessagesListAdapter? = null @@ -2320,28 +2319,20 @@ class ChatController(args: Bundle) : @SuppressLint("NotifyDataSetChanged") @Suppress("Detekt.TooGenericExceptionCaught") override fun onNext(response: Response<*>) { - // when fetching history in between the regular polling, this is set to false!! -> bug? pullChatMessagesPending = false Log.d(TAG, "pullChatMessagesPending was set to false") when (response.code()) { HTTP_CODE_NOT_MODIFIED -> { - Log.d(TAG, "pullChatMessages - HTTP_CODE_NOT_MODIFIED. lookIntoFuture=$lookIntoFuture") + Log.d(TAG, "pullChatMessages - HTTP_CODE_NOT_MODIFIED.") if (lookIntoFuture) { - Log.d(TAG, "recursive call to pullChatMessages. lookIntoFuture=$lookIntoFuture") + Log.d(TAG, "recursive call to pullChatMessages.") pullChatMessages(true, setReadMarker, xChatLastCommonRead) - } else { - Log.d(TAG, "when is this reached?") - historyRead = true - pullChatMessages(true) } } HTTP_CODE_PRECONDITION_FAILED -> { - Log.d( - TAG, - "pullChatMessages - HTTP_CODE_PRECONDITION_FAILED. lookIntoFuture=$lookIntoFuture" - ) + Log.d(TAG, "pullChatMessages - HTTP_CODE_PRECONDITION_FAILED.") if (lookIntoFuture) { futurePreconditionFailed = true @@ -2350,7 +2341,7 @@ class ChatController(args: Bundle) : } } HTTP_CODE_OK -> { - Log.d(TAG, "pullChatMessages - HTTP_CODE_OK. lookIntoFuture=$lookIntoFuture") + Log.d(TAG, "pullChatMessages - HTTP_CODE_OK.") val chatOverall = response.body() as ChatOverall? val chatMessageList = handleSystemMessages(chatOverall?.ocs!!.data!!) @@ -2378,7 +2369,7 @@ class ChatController(args: Bundle) : adapter?.notifyDataSetChanged() if (isFirstMessagesProcessing || lookIntoFuture) { - Log.d(TAG, "recursive call to pullChatMessages. lookIntoFuture=$lookIntoFuture") + Log.d(TAG, "recursive call to pullChatMessages") pullChatMessages(true, true, xChatLastCommonRead) } } @@ -2617,10 +2608,8 @@ class ChatController(args: Bundle) : } override fun onLoadMore(page: Int, totalItemsCount: Int) { - if (!historyRead) { - Log.d(TAG, "requested onLoadMore to pullChatMessages with lookIntoFuture=false") - pullChatMessages(false) - } + Log.d(TAG, "requested onLoadMore to pullChatMessages with lookIntoFuture=false") + pullChatMessages(false) } override fun format(date: Date): String {