~aleteoryx/muditaos

eaedd79f0ac4e60583d46ceeeab9dd698078fca1 — Lukasz Mastalerz 2 years ago fb16f5d
[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.
M module-db/Interface/ContactRecord.cpp => module-db/Interface/ContactRecord.cpp +10 -3
@@ 1471,12 1471,12 @@ auto ContactRecordInterface::MergeContactsList(std::vector<ContactRecord> &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<ContactReco
            LOG_WARN("Contact with multiple numbers detected - ignoring all numbers except first");
        }
        auto matchedNumber = numberMatcher.bestMatch(contact.numbers[0].number, utils::PhoneNumber::Match::POSSIBLE);
        if (matchedNumber.has_value()) {
        if (matchedNumber.has_value() and !matchedNumberRefersToTemporary(matchedNumber.value())) {
            duplicates.push_back(contact);
        }
        else {


@@ 1547,6 1547,13 @@ auto ContactRecordInterface::verifyTemporary(ContactRecord &record) -> 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<std::uint32_t> &oldNumberIDs, std::vector<ContactRecord::Number> &newNumbers) -> bool
{

M module-db/Interface/ContactRecord.hpp => module-db/Interface/ContactRecord.hpp +2 -0
@@ 302,6 302,8 @@ class ContactRecordInterface : public RecordInterface<ContactRecord, ContactReco
    auto addOrUpdateRingtone(std::uint32_t contactID, std::uint32_t ringtoneID, const ContactRecord &contact)
        -> std::optional<std::uint32_t>;

    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
     *

M pure_changelog.md => pure_changelog.md +1 -0
@@ 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]