~aleteoryx/muditaos

d7c8a8a6bfbcd8735df9d62bf4f0a2083e488d5c — Lukasz Mastalerz 2 years ago 942b837
[CP-1210] Contacts imported from SIM dont show up in Mudita Center

Fix for imported contacts from SIM don't show up in Mudita Center.
Added functionality to send notification after all imported contacts are
added to the database.
M module-apps/application-settings/models/network/SimContactsRepository.cpp => module-apps/application-settings/models/network/SimContactsRepository.cpp +12 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SimContactsRepository.hpp"


@@ 93,11 93,15 @@ void SimContactsRepository::save(const std::vector<bool> &selectedContacts,
        if (result == nullptr) {
            return false;
        }
        for (const auto &r : result->getResult()) {
            sendNotification(r);
        }
        if (callback) {
            callback();
        }
        return true;
    });

    task->execute(application, this);
}



@@ 141,6 145,13 @@ void SimContactsRepository::updateImportedRecords(const std::vector<cellular::Si
#endif
}

void SimContactsRepository::sendNotification(const NotificationData &notificationData)
{
    auto notificationMessage = std::make_shared<db::NotificationMessage>(
        db::Interface::Name::Contact, notificationData.first, notificationData.second);
    application->bus.sendMulticast(notificationMessage, sys::BusChannel::ServiceDBNotifications);
}

#if DEBUG_SIM_IMPORT_DATA == 1
void SimContactsRepository::printRecordsData(const std::string &name, const std::vector<ContactRecord> &data)
{

M module-apps/application-settings/models/network/SimContactsRepository.hpp => module-apps/application-settings/models/network/SimContactsRepository.hpp +5 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 27,6 27,7 @@ class AbstractSimContactsRepository
class SimContactsRepository : public AbstractSimContactsRepository, public app::AsyncCallbackReceiver
{
  public:
    using NotificationData = std::pair<db::Query::Type, uint32_t>;
    explicit SimContactsRepository(app::ApplicationCommon *application);

    const std::vector<ContactRecord> &getImportedRecords() override;


@@ 37,6 38,9 @@ class SimContactsRepository : public AbstractSimContactsRepository, public app::
    void findDuplicates(const std::vector<bool> &selectedContacts, OnDupplicatesCheckCallback callback) override;
    void updateImportedRecords(const std::vector<cellular::SimContact> &simData);

  protected:
    void sendNotification(const NotificationData &notificationData);

  private:
    std::vector<ContactRecord> importedRecords;
    std::vector<ContactRecord> uniqueRecords;

M module-apps/apps-common/AsyncTask.cpp => module-apps/apps-common/AsyncTask.cpp +1 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "AsyncTask.hpp"

M module-db/Interface/ContactRecord.cpp => module-db/Interface/ContactRecord.cpp +11 -4
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ContactRecord.hpp"


@@ 1471,8 1471,10 @@ auto ContactRecordInterface::GetNumbersIdsByContact(std::uint32_t contactId) -> 
    return numbersIds;
}

auto ContactRecordInterface::MergeContactsList(std::vector<ContactRecord> &contacts) -> bool
auto ContactRecordInterface::MergeContactsList(std::vector<ContactRecord> &contacts)
    -> std::vector<std::pair<db::Query::Type, uint32_t>>
{
    std::vector<std::pair<db::Query::Type, uint32_t>> dataForNotification{};
    auto numberMatcher = buildNumberMatcher(NumberMatcherPageSize);

    for (auto &contact : contacts) {


@@ 1485,18 1487,23 @@ auto ContactRecordInterface::MergeContactsList(std::vector<ContactRecord> &conta
        if (!matchedNumber.has_value()) {
            if (!Add(contact)) {
                LOG_ERROR("Contacts list merge fail when adding the contact.");
                return false;
            }
            else {
                dataForNotification.push_back({db::Query::Type::Create, contactDB->getLastInsertRowId()});
            }
        }
        else {
            // Complete override of the contact data
            contact.ID = matchedNumber->getContactID();
            dataForNotification.push_back({db::Query::Type::Update, contact.ID});

            Update(contact);
            // Rebuild number matcher
            numberMatcher = buildNumberMatcher(NumberMatcherPageSize);
        }
    }
    return true;

    return dataForNotification;
}

auto ContactRecordInterface::CheckContactsListDuplicates(std::vector<ContactRecord> &contacts)

M module-db/Interface/ContactRecord.hpp => module-db/Interface/ContactRecord.hpp +2 -2
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 227,7 227,7 @@ class ContactRecordInterface : public RecordInterface<ContactRecord, ContactReco
     * @param contacts vector of contacts with single number
     * @return boolean status
     */
    auto MergeContactsList(std::vector<ContactRecord> &contacts) -> bool;
    auto MergeContactsList(std::vector<ContactRecord> &contacts) -> std::vector<std::pair<db::Query::Type, uint32_t>>;

    /**
     * @brief Check which contacts in vector are duplicating contacts in DB

M module-db/queries/phonebook/QueryMergeContactsList.cpp => module-db/queries/phonebook/QueryMergeContactsList.cpp +8 -2
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "QueryMergeContactsList.hpp"


@@ 15,9 15,15 @@ std::vector<ContactRecord> &MergeContactsList::getContactsList()
    return contacts;
}

MergeContactsListResult::MergeContactsListResult(bool result) : result(result)
MergeContactsListResult::MergeContactsListResult(const std::vector<std::pair<db::Query::Type, uint32_t>> &addedContacts)
    : addedContacts(addedContacts)
{}

std::vector<std::pair<db::Query::Type, uint32_t>> &MergeContactsListResult::getResult()
{
    return addedContacts;
}

[[nodiscard]] auto MergeContactsList::debugInfo() const -> std::string
{
    return "MergeContactsList";

M module-db/queries/phonebook/QueryMergeContactsList.hpp => module-db/queries/phonebook/QueryMergeContactsList.hpp +4 -7
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 28,15 28,12 @@ namespace db::query
    class MergeContactsListResult : public QueryResult
    {
      public:
        MergeContactsListResult(bool result);
        [[nodiscard]] auto getResult() const noexcept -> bool
        {
            return result;
        }
        MergeContactsListResult(const std::vector<std::pair<db::Query::Type, uint32_t>> &addedContacts);
        std::vector<std::pair<db::Query::Type, uint32_t>> &getResult();
        [[nodiscard]] auto debugInfo() const -> std::string override;

      private:
        bool result = false;
        std::vector<std::pair<db::Query::Type, uint32_t>> addedContacts{};
    };

}; // namespace db::query

M module-db/tests/ContactsRecord_tests.cpp => module-db/tests/ContactsRecord_tests.cpp +4 -4
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "common.hpp"


@@ 523,7 523,7 @@ TEST_CASE("Contacts list merge")
                std::vector<ContactRecord::Number>({ContactRecord::Number(rawContact.first, std::string(""))});
            contacts.push_back(record);
        }
        REQUIRE(records.MergeContactsList(contacts));
        REQUIRE(!records.MergeContactsList(contacts).empty());

        // Validate if non-overlapping were appended to DB
        REQUIRE(records.GetCount() == (rawContactsInitial.size() + rawContactsToAdd.size()));


@@ 565,7 565,7 @@ TEST_CASE("Contacts list merge")
                std::vector<ContactRecord::Number>({ContactRecord::Number(rawContact.first, std::string(""))});
            contacts.push_back(record);
        }
        REQUIRE(records.MergeContactsList(contacts));
        REQUIRE(!records.MergeContactsList(contacts).empty());

        REQUIRE(records.GetCount() == (rawContactsInitial.size() + numberOfNewContacts));



@@ 612,7 612,7 @@ TEST_CASE("Contacts list merge - advanced cases")
        record.primaryName = rawContact.second;
        record.numbers = std::vector<ContactRecord::Number>({ContactRecord::Number(rawContact.first, std::string(""))});
        contacts.push_back(record);
        REQUIRE(records.MergeContactsList(contacts));
        REQUIRE(!records.MergeContactsList(contacts).empty());

        REQUIRE(records.GetCount() == 1);


M pure_changelog.md => pure_changelog.md +3 -0
@@ 45,6 45,9 @@
* Fixed broken French translation on 'Configure passcode' screen in Onboarding
* Fixed time disappearing in SMS thread
* Fixed scrollbar behavior in call log view
* Fixed contacts imported from SIM do not show up in Mudita Center 

### Added

## [1.5.0 2022-12-20]


M tools/misc => tools/misc +1 -1
@@ 1,1 1,1 @@
Subproject commit eeae49f9d885b6315ca1c4c912108066b5e2388b
Subproject commit 82dce5ad5558a6df4c3f1583ef4e5908ac5fcd9d