From d7c8a8a6bfbcd8735df9d62bf4f0a2083e488d5c Mon Sep 17 00:00:00 2001 From: Lukasz Mastalerz Date: Wed, 25 Jan 2023 13:18:36 +0100 Subject: [PATCH] [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. --- .../models/network/SimContactsRepository.cpp | 13 ++++++++++++- .../models/network/SimContactsRepository.hpp | 6 +++++- module-apps/apps-common/AsyncTask.cpp | 2 +- module-db/Interface/ContactRecord.cpp | 15 +++++++++++---- module-db/Interface/ContactRecord.hpp | 4 ++-- .../queries/phonebook/QueryMergeContactsList.cpp | 10 ++++++++-- .../queries/phonebook/QueryMergeContactsList.hpp | 11 ++++------- module-db/tests/ContactsRecord_tests.cpp | 8 ++++---- pure_changelog.md | 3 +++ tools/misc | 2 +- 10 files changed, 51 insertions(+), 23 deletions(-) diff --git a/module-apps/application-settings/models/network/SimContactsRepository.cpp b/module-apps/application-settings/models/network/SimContactsRepository.cpp index a815b6ef7..6697fab45 100644 --- a/module-apps/application-settings/models/network/SimContactsRepository.cpp +++ b/module-apps/application-settings/models/network/SimContactsRepository.cpp @@ -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 &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( + 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 &data) { diff --git a/module-apps/application-settings/models/network/SimContactsRepository.hpp b/module-apps/application-settings/models/network/SimContactsRepository.hpp index e2ce413cc..8af2004d2 100644 --- a/module-apps/application-settings/models/network/SimContactsRepository.hpp +++ b/module-apps/application-settings/models/network/SimContactsRepository.hpp @@ -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; explicit SimContactsRepository(app::ApplicationCommon *application); const std::vector &getImportedRecords() override; @@ -37,6 +38,9 @@ class SimContactsRepository : public AbstractSimContactsRepository, public app:: void findDuplicates(const std::vector &selectedContacts, OnDupplicatesCheckCallback callback) override; void updateImportedRecords(const std::vector &simData); + protected: + void sendNotification(const NotificationData ¬ificationData); + private: std::vector importedRecords; std::vector uniqueRecords; diff --git a/module-apps/apps-common/AsyncTask.cpp b/module-apps/apps-common/AsyncTask.cpp index a29426b0b..c5321940b 100644 --- a/module-apps/apps-common/AsyncTask.cpp +++ b/module-apps/apps-common/AsyncTask.cpp @@ -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" diff --git a/module-db/Interface/ContactRecord.cpp b/module-db/Interface/ContactRecord.cpp index e0a852626..d15bf1827 100644 --- a/module-db/Interface/ContactRecord.cpp +++ b/module-db/Interface/ContactRecord.cpp @@ -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 &contacts) -> bool +auto ContactRecordInterface::MergeContactsList(std::vector &contacts) + -> std::vector> { + std::vector> dataForNotification{}; auto numberMatcher = buildNumberMatcher(NumberMatcherPageSize); for (auto &contact : contacts) { @@ -1485,18 +1487,23 @@ auto ContactRecordInterface::MergeContactsList(std::vector &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 &contacts) diff --git a/module-db/Interface/ContactRecord.hpp b/module-db/Interface/ContactRecord.hpp index 1647d2933..0ffe5ea73 100644 --- a/module-db/Interface/ContactRecord.hpp +++ b/module-db/Interface/ContactRecord.hpp @@ -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 &contacts) -> bool; + auto MergeContactsList(std::vector &contacts) -> std::vector>; /** * @brief Check which contacts in vector are duplicating contacts in DB diff --git a/module-db/queries/phonebook/QueryMergeContactsList.cpp b/module-db/queries/phonebook/QueryMergeContactsList.cpp index e7397fa16..9c0fab7a0 100644 --- a/module-db/queries/phonebook/QueryMergeContactsList.cpp +++ b/module-db/queries/phonebook/QueryMergeContactsList.cpp @@ -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 &MergeContactsList::getContactsList() return contacts; } -MergeContactsListResult::MergeContactsListResult(bool result) : result(result) +MergeContactsListResult::MergeContactsListResult(const std::vector> &addedContacts) + : addedContacts(addedContacts) {} +std::vector> &MergeContactsListResult::getResult() +{ + return addedContacts; +} + [[nodiscard]] auto MergeContactsList::debugInfo() const -> std::string { return "MergeContactsList"; diff --git a/module-db/queries/phonebook/QueryMergeContactsList.hpp b/module-db/queries/phonebook/QueryMergeContactsList.hpp index e3c25d5f7..ff1102b3a 100644 --- a/module-db/queries/phonebook/QueryMergeContactsList.hpp +++ b/module-db/queries/phonebook/QueryMergeContactsList.hpp @@ -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> &addedContacts); + std::vector> &getResult(); [[nodiscard]] auto debugInfo() const -> std::string override; private: - bool result = false; + std::vector> addedContacts{}; }; }; // namespace db::query diff --git a/module-db/tests/ContactsRecord_tests.cpp b/module-db/tests/ContactsRecord_tests.cpp index 8bb4b957e..3565628b3 100644 --- a/module-db/tests/ContactsRecord_tests.cpp +++ b/module-db/tests/ContactsRecord_tests.cpp @@ -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(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(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(rawContact.first, std::string(""))}); contacts.push_back(record); - REQUIRE(records.MergeContactsList(contacts)); + REQUIRE(!records.MergeContactsList(contacts).empty()); REQUIRE(records.GetCount() == 1); diff --git a/pure_changelog.md b/pure_changelog.md index 6301a3c68..0294bc7be 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -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] diff --git a/tools/misc b/tools/misc index eeae49f9d..82dce5ad5 160000 --- a/tools/misc +++ b/tools/misc @@ -1 +1 @@ -Subproject commit eeae49f9d885b6315ca1c4c912108066b5e2388b +Subproject commit 82dce5ad5558a6df4c3f1583ef4e5908ac5fcd9d