@@ -270,20 +270,27 @@ class OfflineFirstChatRepository @Inject constructor(
270270 delay(INSURANCE_REQUEST_DELAY )
271271 Log .d(TAG , " execute insurance request with latestKnownMessageIdFromSync: $latestKnownMessageIdFromSync " )
272272
273- var fieldMap = getFieldMap(
274- lookIntoFuture = true ,
275- timeout = 0 ,
276- includeLastKnown = false ,
277- lastKnown = latestKnownMessageIdFromSync.toInt(),
278- limit = 200
279- )
280- val networkParams = Bundle ()
281- networkParams.putSerializable(BundleKeys .KEY_FIELD_MAP , fieldMap)
282-
283- getAndPersistMessages(networkParams)
273+ fetchNewMessages()
284274 }
285275 }
286276
277+ /* *
278+ * Fetches messages newer than latest known message
279+ */
280+ private suspend fun fetchNewMessages () {
281+ var fieldMap = getFieldMap(
282+ lookIntoFuture = true ,
283+ timeout = 0 ,
284+ includeLastKnown = false ,
285+ lastKnown = latestKnownMessageIdFromSync.toInt(),
286+ limit = 200
287+ )
288+ val networkParams = Bundle ()
289+ networkParams.putSerializable(BundleKeys .KEY_FIELD_MAP , fieldMap)
290+
291+ getAndPersistMessages(networkParams)
292+ }
293+
287294 override suspend fun loadMoreMessages (
288295 anchorMessageId : Long ,
289296 direction : ChatMessageRepository .LoadMoreDirection ,
@@ -594,6 +601,16 @@ class OfflineFirstChatRepository @Inject constructor(
594601 updateBlocks(newChatBlock)
595602 }
596603
604+ /* *
605+ * Returns true if all system messages do not require translation.
606+ * Ignores other message types.
607+ */
608+ private fun isUntranslatedSystemMessage (messagesJson : List <ChatMessageJson >): Boolean =
609+ messagesJson.all {
610+ it.systemMessageType == ChatMessage .SystemMessageType .DUMMY ||
611+ it.systemMessageType in ChatMessage .SYSTEM_MESSAGE_TYPE_UNTRANSLATED
612+ }
613+
597614 private suspend fun handleSystemMessagesThatAffectDatabase (messagesJson : List <ChatMessageJson >) {
598615 var hasPinnedMessageChange = false
599616 messagesJson.forEach { messageJson ->
@@ -1010,10 +1027,18 @@ class OfflineFirstChatRepository @Inject constructor(
10101027 }
10111028
10121029 override suspend fun onSignalingChatMessageReceived (chatMessages : List <ChatMessageJson >) {
1030+ // check if we need to get user specific data from the backend
1031+ if (! isUntranslatedSystemMessage(chatMessages) ||
1032+ chatMessages.any { it.messageParameters?.containsKey(" file" ) == true }) {
1033+ Log .d(TAG , " onSignalingChatMessageReceived force data refresh" )
1034+ fetchNewMessages()
1035+ return
1036+ }
1037+
10131038 persistChatMessagesAndHandleSystemMessages(chatMessages, emitOnIncoming = true )
10141039
10151040 // we assume that the signaling messages are on top of the latest chatblock and include them inside it.
1016- // If for whatever reason the assume was not correct and there would be messages in between, the
1041+ // If for whatever reason the assumption was not correct and there would be messages in between, the
10171042 // insurance request should fix this by adding the missing messages and updating the chatblocks.
10181043 val latestChatBlock = chatBlocksDao.getLatestChatBlock(internalConversationId, threadId)
10191044 latestChatBlock.first()?.apply {
0 commit comments