From b757164c6d7dc8f8c054aa34817e548691a00052 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 9 Aug 2024 09:52:44 +0200 Subject: [PATCH] only delay readStatus handling for initial loading Signed-off-by: Marcel Hibbe --- .../data/network/OfflineFirstChatRepository.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt b/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt index 032f2b455..8006cd5bd 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/data/network/OfflineFirstChatRepository.kt @@ -123,18 +123,19 @@ class OfflineFirstChatRepository @Inject constructor( internalConversationId, chatDao.getNewestMessageId(internalConversationId) ) - updateUiForLastCommonRead() + updateUiForLastCommonRead(200) initMessagePolling() } - private fun updateUiForLastCommonRead(){ + private fun updateUiForLastCommonRead(delay: Long) { scope.launch { - // TODO improve... // delay is a dirty workaround to make sure messages are added to adapter on initial load before setting - // their read status. - // This workaround causes that the checkmarks seem to switch whenever sending a message - delay(200) + // their read status(otherwise there is a race condition between adding messages and setting their read + // status). + if (delay > 0) { + delay(delay) + } newXChatLastCommonRead?.let { _lastCommonReadFlow.emit(it) } @@ -165,7 +166,7 @@ class OfflineFirstChatRepository @Inject constructor( } showLast100MessagesBefore(internalConversationId, beforeMessageId) - updateUiForLastCommonRead() + updateUiForLastCommonRead(0) } override fun initMessagePolling(): Job = @@ -199,7 +200,7 @@ class OfflineFirstChatRepository @Inject constructor( _messageFlow.emit(pair) } - updateUiForLastCommonRead() + updateUiForLastCommonRead(0) // Process read status if not null // val lastKnown = datastore.getLastKnownId(internalConversationId, 0)