From adf18020c1750095a6490aadb96034dc353eb04c Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Wed, 16 Oct 2024 14:20:45 +0200 Subject: [PATCH] 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 --- .../data/network/OfflineFirstConversationsRepository.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/conversationlist/data/network/OfflineFirstConversationsRepository.kt b/app/src/main/java/com/nextcloud/talk/conversationlist/data/network/OfflineFirstConversationsRepository.kt index c9d276201..f02eeff40 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationlist/data/network/OfflineFirstConversationsRepository.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationlist/data/network/OfflineFirstConversationsRepository.kt @@ -131,10 +131,12 @@ class OfflineFirstConversationsRepository @Inject constructor( } private suspend fun deleteLeftConversations(conversationsFromSync: List) { + 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) }