@@ -140,12 +140,15 @@ class OfflineFirstChatRepository @Inject constructor(
140140 this .conversationModel = conversationModel
141141 }
142142
143- override fun initScopeAndLoadInitialMessages (withNetworkParams : Bundle ) {
143+ override fun initScopeAndLoadInitialMessages (withNetworkParams : Bundle , hasHighPerformanceBackend : Boolean ) {
144144 scope = CoroutineScope (Dispatchers .IO )
145- loadInitialMessages(withNetworkParams)
145+ loadInitialMessages(
146+ withNetworkParams,
147+ hasHighPerformanceBackend
148+ )
146149 }
147150
148- private fun loadInitialMessages (withNetworkParams : Bundle ): Job =
151+ private fun loadInitialMessages (withNetworkParams : Bundle , hasHighPerformanceBackend : Boolean ): Job =
149152 scope.launch {
150153 Log .d(TAG , " ---- loadInitialMessages ------------" )
151154 newXChatLastCommonRead = conversationModel.lastCommonReadMessage
@@ -161,19 +164,27 @@ class OfflineFirstChatRepository @Inject constructor(
161164 val weHaveAtLeastTheLastReadMessage = newestMessageIdFromDb >= conversationModel.lastReadMessage.toLong()
162165 Log .d(TAG , " weAlreadyHaveSomeOfflineMessages:$weAlreadyHaveSomeOfflineMessages " )
163166 Log .d(TAG , " weHaveAtLeastTheLastReadMessage:$weHaveAtLeastTheLastReadMessage " )
167+ Log .d(TAG , " hasHighPerformanceBackend:$hasHighPerformanceBackend " )
164168
165- if (weAlreadyHaveSomeOfflineMessages && weHaveAtLeastTheLastReadMessage) {
169+ if (weAlreadyHaveSomeOfflineMessages && weHaveAtLeastTheLastReadMessage && ! hasHighPerformanceBackend ) {
166170 Log .d(
167171 TAG ,
168172 " Initial online request is skipped because offline messages are up to date" +
169173 " until lastReadMessage"
170174 )
171175
172- // This is a problem! No long polling should be done when we have the HPB. How to initially get the
173- // messages newer than TheLastReadMessage?
174- Log .d(TAG , " For messages newer than lastRead, lookIntoFuture will load them." )
176+ // For messages newer than lastRead, lookIntoFuture will load them.
177+ // We must only end up here when NO HPB is used!
178+ // If a HPB is used, longPolling is not available to handle loading of newer messages.
179+ // When a HPB is used the initial request must be made.
175180 } else {
176- if (! weAlreadyHaveSomeOfflineMessages) {
181+ if (hasHighPerformanceBackend) {
182+ Log .d(
183+ TAG ,
184+ " An online request for newest 100 messages is made because HPB is used (No long " +
185+ " polling available to catch up with messages newer than last read.)"
186+ )
187+ } else if (! weAlreadyHaveSomeOfflineMessages) {
177188 Log .d(TAG , " An online request for newest 100 messages is made because offline chat is empty" )
178189 if (networkMonitor.isOnline.value.not ()) {
179190 _generalUIFlow .emit(ChatActivity .NO_OFFLINE_MESSAGES_FOUND )
@@ -208,8 +219,9 @@ class OfflineFirstChatRepository @Inject constructor(
208219
209220 handleMessagesFromDb(newestMessageIdFromDb)
210221
211- // temp disabled to test only signaling
212- // initMessagePolling(newestMessageIdFromDb)
222+ if (! hasHighPerformanceBackend) {
223+ initMessagePolling(newestMessageIdFromDb)
224+ }
213225 }
214226
215227 private suspend fun handleMessagesFromDb (newestMessageIdFromDb : Long ) {
0 commit comments