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 a815b6ef73dff706ab6ad91b3ff4e8473ac23a9f..6697fab45e3358fc5aa6fec007527317029d1174 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 e2ce413cc40d5fe729e58aa619b270e7620f4e33..8af2004d21333f466f78fa784553bc97bcac9341 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 a29426b0b2dddd45af63e7e568d40432d39baa41..c5321940b27e9dd258d6d446dc04470efdf3fe6d 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 e0a8526267e0af83ea945b0fbdc95d0b7962122b..d15bf18271416514223446ef3157e7c4823caa7b 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 1647d2933074a89c30e48708e7d534d2466791dd..0ffe5ea73ea83efc49fc5c32cc5668445428ff26 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 e7397fa1607218f85e35d62506ea8e334145b28e..9c0fab7a042dbb24216fc72e16e47a3e7157d377 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 e3c25d5f714a804665f000e169cdf57c87ef617a..ff1102b3a917315b14d0a0cd620b5bdb7425f2bc 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 8bb4b957e7291fc96d79e1ba3c9ea42ecf8c5162..3565628b326d50dcfe044c1e1f670b77e21493d5 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 6301a3c68e797f6928ca36bb7b38a5dda8511279..0294bc7beefba004c23f105c0a55b3c91550a5f6 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 eeae49f9d885b6315ca1c4c912108066b5e2388b..82dce5ad5558a6df4c3f1583ef4e5908ac5fcd9d 160000 --- a/tools/misc +++ b/tools/misc @@ -1 +1 @@ -Subproject commit eeae49f9d885b6315ca1c4c912108066b5e2388b +Subproject commit 82dce5ad5558a6df4c3f1583ef4e5908ac5fcd9d