From eaedd79f0ac4e60583d46ceeeab9dd698078fca1 Mon Sep 17 00:00:00 2001 From: Lukasz Mastalerz Date: Tue, 31 Jan 2023 19:10:43 +0100 Subject: [PATCH] [MOS-884] Importing contacts from SIM card more than once Fix for importing and removing contacts from SIM card causes issue that imported contacts didn't have a name and could by multiplied. --- module-db/Interface/ContactRecord.cpp | 13 ++++++++++--- module-db/Interface/ContactRecord.hpp | 2 ++ pure_changelog.md | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/module-db/Interface/ContactRecord.cpp b/module-db/Interface/ContactRecord.cpp index 6a1002c66d73ebbd8b6c239b92dab96da52cba4d..454fa875fbee2960f5c49ebc6385e889d5b2468f 100644 --- a/module-db/Interface/ContactRecord.cpp +++ b/module-db/Interface/ContactRecord.cpp @@ -1471,12 +1471,12 @@ auto ContactRecordInterface::MergeContactsList(std::vector &conta } auto matchedNumber = numberMatcher.bestMatch(contact.numbers[0].number, utils::PhoneNumber::Match::POSSIBLE); - if (!matchedNumber.has_value()) { + if (!matchedNumber.has_value() or matchedNumberRefersToTemporary(matchedNumber.value())) { if (!Add(contact)) { LOG_ERROR("Contacts list merge fail when adding the contact."); } else { - dataForNotification.push_back({db::Query::Type::Create, contactDB->getLastInsertRowId()}); + dataForNotification.push_back({db::Query::Type::Create, contact.ID}); } } else { @@ -1506,7 +1506,7 @@ auto ContactRecordInterface::CheckContactsListDuplicates(std::vector bool return isTemporary; } +auto ContactRecordInterface::matchedNumberRefersToTemporary(const ContactNumberHolder &matchedNumber) -> bool +{ + auto contact = GetByNumberID(matchedNumber.getNumberID()); + + return contact.has_value() and contact->isTemporary(); +} + auto ContactRecordInterface::changeNumberRecordInPlaceIfCountryCodeIsOnlyDifferent( const std::vector &oldNumberIDs, std::vector &newNumbers) -> bool { diff --git a/module-db/Interface/ContactRecord.hpp b/module-db/Interface/ContactRecord.hpp index abed2db4c519fc0f56e7f955efa230bc82dd8975..ebc71a9df0c6413f7276c6600b457ce4aedaa2a8 100644 --- a/module-db/Interface/ContactRecord.hpp +++ b/module-db/Interface/ContactRecord.hpp @@ -302,6 +302,8 @@ class ContactRecordInterface : public RecordInterface std::optional; + auto matchedNumberRefersToTemporary(const ContactNumberHolder &matchedNumber) -> bool; + /** * @brief Changing number table record in place if new number is same as old number but with/without country code * diff --git a/pure_changelog.md b/pure_changelog.md index d319436914bbe865254870e93b1e2e259e966784..300f0d05faa56213efa040a7a7ae4962477c32b7 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -57,6 +57,7 @@ * Fixed templates list not looping * Fixed inability to import contacts from Orange SIM cards * Fixed improper asterisk button behavior when adding new contact +* Fixed for contacts removed and imported from SIM card once again were added to database without names ## [1.5.0 2022-12-20]