@@ -208,7 +208,7 @@ class OfflineFirstChatRepository @Inject constructor(
208208 withNetworkParams.putString(BundleKeys .KEY_ROOM_TOKEN , conversationModel.token)
209209
210210 Log .d(TAG , " Starting online request for initial loading" )
211- val chatMessageEntities = sync (withNetworkParams)
211+ val chatMessageEntities = getMessages (withNetworkParams)
212212 if (chatMessageEntities == null ) {
213213 Log .e(TAG , " initial loading of messages failed" )
214214 }
@@ -220,7 +220,9 @@ class OfflineFirstChatRepository @Inject constructor(
220220 handleMessagesFromDb(newestMessageIdFromDb)
221221
222222 if (! hasHighPerformanceBackend) {
223- initMessagePolling(newestMessageIdFromDb)
223+ initLongPolling(newestMessageIdFromDb)
224+ } else {
225+ initRepeatingInsuranceRequest(newestMessageIdFromDb)
224226 }
225227 }
226228
@@ -314,16 +316,16 @@ class OfflineFirstChatRepository @Inject constructor(
314316
315317 if (loadFromServer) {
316318 Log .d(TAG , " Starting online request for loadMoreMessages" )
317- sync (withNetworkParams)
319+ getMessages (withNetworkParams)
318320 }
319321
320322 showMessagesBefore(internalConversationId, beforeMessageId, DEFAULT_MESSAGES_LIMIT )
321323 updateUiForLastCommonRead()
322324 }
323325
324- override fun initMessagePolling (initialMessageId : Long ): Job =
326+ override fun initLongPolling (initialMessageId : Long ): Job =
325327 scope.launch {
326- Log .d(TAG , " ---- initMessagePolling ------------" )
328+ Log .d(TAG , " ---- initLongPolling ------------" )
327329
328330 Log .d(TAG , " newestMessage: $initialMessageId " )
329331
@@ -345,11 +347,11 @@ class OfflineFirstChatRepository @Inject constructor(
345347 Thread .sleep(HALF_SECOND )
346348 } else {
347349 // sync database with server
348- // (This is a long blocking call because long polling (lookIntoFuture) is set)
350+ // (This is a long blocking call because long polling (lookIntoFuture and timeout ) is set)
349351 networkParams.putSerializable(BundleKeys .KEY_FIELD_MAP , fieldMap)
350352
351353 Log .d(TAG , " Starting online request for long polling" )
352- val resultsFromSync = sync (networkParams)
354+ val resultsFromSync = getMessages (networkParams)
353355 if (! resultsFromSync.isNullOrEmpty()) {
354356 val chatMessages = resultsFromSync.map(ChatMessageEntity ::asModel)
355357
@@ -392,6 +394,17 @@ class OfflineFirstChatRepository @Inject constructor(
392394 }
393395 }
394396
397+ private fun initRepeatingInsuranceRequest (initialMessageId : Long ) {
398+ scope.launch {
399+ Log .d(TAG , " ---- initRepeatingInsuranceRequest ------------" )
400+
401+ Log .d(TAG , " newestMessage: $initialMessageId " )
402+
403+
404+
405+ }
406+ }
407+
395408 private suspend fun handleNewAndTempMessages (
396409 receivedChatMessages : List <ChatMessage >,
397410 lookIntoFuture : Boolean ,
@@ -518,7 +531,7 @@ class OfflineFirstChatRepository @Inject constructor(
518531 bundle.putSerializable(BundleKeys .KEY_FIELD_MAP , fieldMap)
519532
520533 Log .d(TAG , " Starting online request for single message (e.g. a reply)" )
521- sync (bundle)
534+ getMessages (bundle)
522535 }
523536 // we cant just expect here that sync succeeded??
524537 return chatDao.getChatMessageForConversation(
@@ -596,7 +609,7 @@ class OfflineFirstChatRepository @Inject constructor(
596609 return null
597610 }
598611
599- private suspend fun sync (bundle : Bundle ): List <ChatMessageEntity >? {
612+ private suspend fun getMessages (bundle : Bundle ): List <ChatMessageEntity >? {
600613 if (! networkMonitor.isOnline.value) {
601614 Log .d(TAG , " Device is offline, can't load chat messages from server" )
602615 return null
0 commit comments