From fb249e45f5cc7b01b236e2671d6df4b92b274a87 Mon Sep 17 00:00:00 2001 From: migulyaev Date: Tue, 12 Sep 2023 18:37:50 +0400 Subject: [PATCH] fix inserting the same contact multiple times --- .../contacts/storage/ContactsRepository.kt | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/tech/relaycorp/letro/contacts/storage/ContactsRepository.kt b/app/src/main/java/tech/relaycorp/letro/contacts/storage/ContactsRepository.kt index 73da146e..7fed8b51 100644 --- a/app/src/main/java/tech/relaycorp/letro/contacts/storage/ContactsRepository.kt +++ b/app/src/main/java/tech/relaycorp/letro/contacts/storage/ContactsRepository.kt @@ -61,11 +61,19 @@ class ContactsRepositoryImpl @Inject constructor( ) if (existingContact == null || existingContact.status <= ContactPairingStatus.REQUEST_SENT) { - contactsDao.insert( - contact.copy( - status = ContactPairingStatus.REQUEST_SENT, - ), - ) + if (existingContact == null) { + contactsDao.insert( + contact.copy( + status = ContactPairingStatus.REQUEST_SENT, + ), + ) + } else { + contactsDao.update( + contact.copy( + status = ContactPairingStatus.REQUEST_SENT + ) + ) + } awalaManager.sendMessage( outgoingMessage = AwalaOutgoingMessage( type = MessageType.ContactPairingRequest,