Skip to content

Commit

Permalink
fix hasHistory logic
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
  • Loading branch information
mahibi committed Jul 25, 2024
1 parent 77fe7a5 commit e4efe37
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,11 @@ class OfflineFirstChatRepository @Inject constructor(
): Boolean {
val loadFromServer: Boolean

// TODO change......
val chatBlock = chatBlocksDao.getChatBlocksContainingMessageId(internalConversationId, beforeMessageId).first().first()
val blockForMessage = updateBlocks(chatBlock) // only get block without to update?!
val blockForMessage: ChatBlockEntity? = chatBlocksDao.getChatBlocksContainingMessageId(
internalConversationId,
beforeMessageId
).first().first()
// val blockForMessage = updateBlocks(chatBlock) // only get block without to update?!

if (blockForMessage == null) {
Log.d(TAG, "No blocks for this message were found so we have to ask server")
Expand Down Expand Up @@ -465,7 +467,7 @@ class OfflineFirstChatRepository @Inject constructor(
)
chatBlocksDao.upsertChatBlock(newChatBlock)

updateBlocks(newChatBlock) // of course only one chat block will be found for this id!!!
updateBlocks(newChatBlock)
} else {
Log.d(TAG, "no data is updated...")
}
Expand Down Expand Up @@ -535,8 +537,8 @@ class OfflineFirstChatRepository @Inject constructor(
val newestIdFromDbChatBlocks =
connectedChatBlocks.maxByOrNull { it.newestMessageId }!!.newestMessageId

// TODO check if one block contains hasHistory=false then also set it for new one
val hasHistory = connectedChatBlocks.first { it.hasHistory }.hasHistory
val hasNoHistory = connectedChatBlocks.any { !it.hasHistory }
val hasHistory = !hasNoHistory
Log.d(TAG, "hasHistory = $hasHistory")

chatBlocksDao.deleteChatBlocks(connectedChatBlocks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ interface ChatBlocksDao {
ORDER BY newestMessageId ASC
"""
)
fun getChatBlocksContainingMessageId(internalConversationId: String, messageId: Long): Flow<List<ChatBlockEntity>>
fun getChatBlocksContainingMessageId(internalConversationId: String, messageId: Long): Flow<List<ChatBlockEntity?>>


@Query(
Expand Down

0 comments on commit e4efe37

Please sign in to comment.