From fe9fd386d7d9afa01bb08ce4a80ec38082a554b6 Mon Sep 17 00:00:00 2001 From: Aleksey Ivanovsky Date: Sat, 19 Oct 2024 16:29:20 +0200 Subject: [PATCH] Fix entry update logic --- .../keepass/kotpass/KotpassNoteDao.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/ivanovsky/passnotes/data/repository/keepass/kotpass/KotpassNoteDao.kt b/app/src/main/kotlin/com/ivanovsky/passnotes/data/repository/keepass/kotpass/KotpassNoteDao.kt index 13252c5f..38db3d3a 100644 --- a/app/src/main/kotlin/com/ivanovsky/passnotes/data/repository/keepass/kotpass/KotpassNoteDao.kt +++ b/app/src/main/kotlin/com/ivanovsky/passnotes/data/repository/keepass/kotpass/KotpassNoteDao.kt @@ -270,7 +270,7 @@ class KotpassNoteDao( .drop(excessiveHistoryItems) .toMutableList() .apply { - add(oldEntry) + add(oldEntry.copy(history = emptyList())) } } else { emptyList() @@ -313,19 +313,17 @@ class KotpassNoteDao( addAll(historyEntry.binaries) } } + .distinctBy { reference -> reference.hash } .toAttachments( allBinaries = oldBinariesMap ) - val newAttachments = mutableListOf() - .apply { - addAll( - newHistory - .flatMap { entry -> entry.binaries } - .toAttachments(allBinaries = oldBinariesMap) - ) - addAll(newNote.attachments) - } + val newHistoryAttachments = newHistory + .flatMap { entry -> entry.binaries } + .toAttachments(allBinaries = oldBinariesMap) + + val newAttachments = (newHistoryAttachments + newNote.attachments) + .distinctBy { attachment -> attachment.hash } val attachmentsDiff = differ.getAttachmentsDiff(oldAttachments, newAttachments) return if (attachmentsDiff.isNotEmpty()) {