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()) {