Fix unintended deletion of conversations (+related messages&chatBlocks)

Mistake was, that the conversations from DB and sync could differ due to values.
E.g. when a user changed the status, the conversations from DB and sync would differ. So there were conversations (+related messages&chatBlocks) deleted sometimes.
This caused bugs that when entering a chat, all data was loaded again.

In the previous implementation (before this PR), this error was only visible in the UI when you were offline (in this case, nothing was displayed!).

To fix the bug, only the internalId's are compared.

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2024-10-16 14:20:45 +02:00
parent 3d37cc0831
commit adf18020c1
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B

View file

@ -131,10 +131,12 @@ class OfflineFirstConversationsRepository @Inject constructor(
}
private suspend fun deleteLeftConversations(conversationsFromSync: List<ConversationEntity>) {
val conversationsFromSyncIds = conversationsFromSync.map { it.internalId }.toSet()
val oldConversationsFromDb = dao.getConversationsForUser(user.id!!).first()
val conversationsToDelete = oldConversationsFromDb.filterNot { conversationsFromSync.contains(it) }
val conversationIdsToDelete = conversationsToDelete.map { it.internalId }
val conversationIdsToDelete = oldConversationsFromDb
.map { it.internalId }
.filterNot { it in conversationsFromSyncIds }
dao.deleteConversations(conversationIdsToDelete)
}