mirror of
https://github.com/nextcloud/talk-android
synced 2025-08-04 02:25:04 +01:00
Merge pull request #4193 from nextcloud/bugfix/4168/doNotPullMessagesWhenOfflineOrPaused
do not try to pull chat messages when offline or paused
This commit is contained in:
commit
9976767591
@ -199,29 +199,31 @@ class OfflineFirstChatRepository @Inject constructor(
|
|||||||
val networkParams = Bundle()
|
val networkParams = Bundle()
|
||||||
|
|
||||||
while (true) {
|
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)
|
||||||
|
|
||||||
// sync database with server (This is a long blocking call because long polling (lookIntoFuture) is set)
|
val resultsFromSync = sync(networkParams)
|
||||||
networkParams.putSerializable(BundleKeys.KEY_FIELD_MAP, fieldMap)
|
if (!resultsFromSync.isNullOrEmpty()) {
|
||||||
|
val chatMessages = resultsFromSync.map(ChatMessageEntity::asModel)
|
||||||
|
val pair = Pair(true, chatMessages)
|
||||||
|
_messageFlow.emit(pair)
|
||||||
|
}
|
||||||
|
|
||||||
val resultsFromSync = sync(networkParams)
|
updateUiForLastCommonRead()
|
||||||
if (!resultsFromSync.isNullOrEmpty()) {
|
|
||||||
val chatMessages = resultsFromSync.map(ChatMessageEntity::asModel)
|
val newestMessage = chatDao.getNewestMessageId(internalConversationId).toInt()
|
||||||
val pair = Pair(true, chatMessages)
|
|
||||||
_messageFlow.emit(pair)
|
// update field map vars for next cycle
|
||||||
|
fieldMap = getFieldMap(
|
||||||
|
lookIntoFuture = true,
|
||||||
|
includeLastKnown = false,
|
||||||
|
setReadMarker = true,
|
||||||
|
lastKnown = newestMessage
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUiForLastCommonRead()
|
|
||||||
|
|
||||||
val newestMessage = chatDao.getNewestMessageId(internalConversationId).toInt()
|
|
||||||
|
|
||||||
// update field map vars for next cycle
|
|
||||||
fieldMap = getFieldMap(
|
|
||||||
lookIntoFuture = true,
|
|
||||||
includeLastKnown = false,
|
|
||||||
setReadMarker = true,
|
|
||||||
lastKnown = newestMessage
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user