Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-20.0] do not try to pull chat messages when offline or paused #4200

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,29 +199,31 @@ class OfflineFirstChatRepository @Inject constructor(
val networkParams = Bundle()

while (true) {
if (!monitor.isOnline.first() || itIsPaused) Thread.sleep(HALF_SECOND)

// sync database with server (This is a long blocking call because long polling (lookIntoFuture) is set)
networkParams.putSerializable(BundleKeys.KEY_FIELD_MAP, fieldMap)

val resultsFromSync = sync(networkParams)
if (!resultsFromSync.isNullOrEmpty()) {
val chatMessages = resultsFromSync.map(ChatMessageEntity::asModel)
val pair = Pair(true, chatMessages)
_messageFlow.emit(pair)
}
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)

val resultsFromSync = sync(networkParams)
if (!resultsFromSync.isNullOrEmpty()) {
val chatMessages = resultsFromSync.map(ChatMessageEntity::asModel)
val pair = Pair(true, chatMessages)
_messageFlow.emit(pair)
}

updateUiForLastCommonRead()
updateUiForLastCommonRead()

val newestMessage = chatDao.getNewestMessageId(internalConversationId).toInt()
val newestMessage = chatDao.getNewestMessageId(internalConversationId).toInt()

// update field map vars for next cycle
fieldMap = getFieldMap(
lookIntoFuture = true,
includeLastKnown = false,
setReadMarker = true,
lastKnown = newestMessage
)
// update field map vars for next cycle
fieldMap = getFieldMap(
lookIntoFuture = true,
includeLastKnown = false,
setReadMarker = true,
lastKnown = newestMessage
)
}
}
}

Expand Down
Loading