do not try to pull chat messages when offline or paused

Otherwise, it resulted in a lot of flickering because _lastCommonReadFlow was emitted every 500ms. And anyway if we know we are offline or paused then it doesn't make sense to execute the sync method.

chain which caused the flickering was:
updateUiForLastCommonRead (_lastCommonReadFlow) -> updateReadStatusOfAllMessages - notifyDataSetChanged -> onBindViewHolder -> IncomingLinkPreviewMessageViewHolder

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-09-11 17:05:07 +02:00
parent e7d596f402
commit 9a14764321
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B

View File

@ -199,8 +199,9 @@ class OfflineFirstChatRepository @Inject constructor(
val networkParams = Bundle()
while (true) {
if (!monitor.isOnline.first() || itIsPaused) Thread.sleep(HALF_SECOND)
if (!monitor.isOnline.first() || itIsPaused) {
Thread.sleep(HALF_SECOND)
} else {
// sync database with server (This is a long blocking call because long polling (lookIntoFuture) is set)
networkParams.putSerializable(BundleKeys.KEY_FIELD_MAP, fieldMap)
@ -224,6 +225,7 @@ class OfflineFirstChatRepository @Inject constructor(
)
}
}
}
private suspend fun hasToLoadPreviousMessagesFromServer(beforeMessageId: Long): Boolean {
val loadFromServer: Boolean