Skip to content

Commit e954716

Browse files
committed
MOPPAND-1660 Fix for adding duplicate recipient.
1 parent b33f016 commit e954716

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

app/src/main/kotlin/ee/ria/DigiDoc/viewmodel/EncryptRecipientViewModel.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class EncryptRecipientViewModel
9292

9393
private fun filterRecipients() =
9494
queryText
95-
.combine(_recipientList) { text, recipients ->
95+
.combine(_recipientList) { text, _ ->
9696
if (!text.isEmpty()) {
9797
var allRecipients: Pair<List<Addressee>, Int> = Pair(listOf(), 0)
9898
try {
@@ -136,14 +136,16 @@ class EncryptRecipientViewModel
136136
) {
137137
val cryptoContainer = sharedContainerViewModel.cryptoContainer.value
138138

139-
if (cryptoContainer?.getRecipients()?.contains(recipient) == true) {
140-
_errorState.postValue(R.string.crypto_recipients_error_exists)
141-
handleIsRecipientAdded(false)
142-
return
143-
} else {
144-
cryptoContainer?.addRecipients(listOf(recipient))
139+
cryptoContainer?.getRecipients()?.forEach {
140+
if (recipient.data.contentEquals(it.data)) {
141+
_errorState.postValue(R.string.crypto_recipients_error_exists)
142+
handleIsRecipientAdded(false)
143+
return
144+
}
145145
}
146146

147+
cryptoContainer?.addRecipients(listOf(recipient))
148+
147149
sharedContainerViewModel.setCryptoContainer(cryptoContainer)
148150
handleIsRecipientAdded(true)
149151
}

0 commit comments

Comments
 (0)