From b006a01853e3ea0d6441552324d18db3a7e68b29 Mon Sep 17 00:00:00 2001 From: rrandomsky Date: Tue, 8 Aug 2023 15:03:23 +0200 Subject: [PATCH] [MOS-1007] Fix for no popup when contact cannot be saved because of same nubers Fix for fix. It add popup when user try to save contact witch practically the same numners (even if having a country code is only difference) --- image/system_a/data/lang/Deutsch.json | 2 + image/system_a/data/lang/English.json | 2 + image/system_a/data/lang/Espanol.json | 2 + image/system_a/data/lang/Francais.json | 2 + image/system_a/data/lang/Polski.json | 2 + image/system_a/data/lang/Svenska.json | 2 + .../windows/PhonebookNewContact.cpp | 17 ++++ .../windows/PhonebookNewContact.hpp | 1 + module-db/Interface/ContactRecord.hpp | 4 +- module-services/service-db/DBServiceAPI.cpp | 23 ++++++ .../include/service-db/DBServiceAPI.hpp | 4 +- products/PurePhone/services/db/ServiceDB.cpp | 77 +++++++++++-------- pure_changelog.md | 1 + source/MessageType.hpp | 11 ++- 14 files changed, 109 insertions(+), 41 deletions(-) diff --git a/image/system_a/data/lang/Deutsch.json b/image/system_a/data/lang/Deutsch.json index 5bf4600b36667ce1f76318349c290aa74ab87233..8eae58dcd878589aab7381bc57766c140dc25589 100644 --- a/image/system_a/data/lang/Deutsch.json +++ b/image/system_a/data/lang/Deutsch.json @@ -369,6 +369,8 @@ "app_phonebook_new_contact_email": "E-Mail", "app_phonebook_new_contact_first_name": "Vorname", "app_phonebook_new_contact_invalid_number": "Dieser Kontakt kann nicht gespeichert werden.

Die von Ihnen eingegebene Telefonnummer

hat ein ung\u00fcltiges Format.
", + "app_phonebook_new_contact_unable_to_save": "Kontakt nicht gespeichert", + "app_phonebook_new_contact_same_numbers": "Trotz der eingegebenen Landesvorwahl sind die Telefonnummern identisch.



Geben Sieeine weitere Nummer ein, um den Kontakt zu speichern.", "app_phonebook_new_contact_last_name": "Nachname", "app_phonebook_new_contact_note": "Notiz", "app_phonebook_new_contact_number": "Nummer", diff --git a/image/system_a/data/lang/English.json b/image/system_a/data/lang/English.json index b21fdc3ddf31755726b05e06faed9e3cff620d31..1b08f74a4d314bae9fbf20f48c1e2ee9aa33feed 100644 --- a/image/system_a/data/lang/English.json +++ b/image/system_a/data/lang/English.json @@ -372,6 +372,8 @@ "app_phonebook_new_contact_email": "Email", "app_phonebook_new_contact_first_name": "First name", "app_phonebook_new_contact_invalid_number": "Cannot save this contact.

The phone number you entered

is in an invalid format.
", + "app_phonebook_new_contact_unable_to_save": "Unable to save contact", + "app_phonebook_new_contact_same_numbers": "Despite the country code entered,

the phone numbers are the same.




Enter another numbers to save

the contact.
", "app_phonebook_new_contact_last_name": "Last name", "app_phonebook_new_contact_note": "Note", "app_phonebook_new_contact_number": "Phone number", diff --git a/image/system_a/data/lang/Espanol.json b/image/system_a/data/lang/Espanol.json index 3bdb0d30961d6e39054921d279e43130aed386c7..59ac464cbe93ebabe170c0853a71434ada0d1c72 100644 --- a/image/system_a/data/lang/Espanol.json +++ b/image/system_a/data/lang/Espanol.json @@ -368,6 +368,8 @@ "app_phonebook_new_contact_email": "Correo electr\u00f3nico", "app_phonebook_new_contact_first_name": "Nombre", "app_phonebook_new_contact_invalid_number": "No se puede guardar este contacto.

El n\u00famero de tel\u00e9fono que ingres\u00f3

tiene un formato no v\u00e1lido.
", + "app_phonebook_new_contact_unable_to_save": "No se pudo guardar el contacto", + "app_phonebook_new_contact_same_numbers": "A pesar del c\u00f3digo de país ingresado, los n\u00fameros de tel\u00e9fono son los mismos.



Ingrese otros n\u00fameros para guardar el contacto.", "app_phonebook_new_contact_last_name": "Apellido", "app_phonebook_new_contact_note": "Nota", "app_phonebook_new_contact_number": "N\u00famero", diff --git a/image/system_a/data/lang/Francais.json b/image/system_a/data/lang/Francais.json index 8219999cbea3bd168dfd67c8b4a01a7d242f6348..fd243c5059b9556ccee771a2f1acafbadb6cf0e0 100644 --- a/image/system_a/data/lang/Francais.json +++ b/image/system_a/data/lang/Francais.json @@ -336,6 +336,8 @@ "app_phonebook_new_contact_email": "Email", "app_phonebook_new_contact_first_name": "Pr\u00e9nom", "app_phonebook_new_contact_invalid_number": "Impossible d'enregistrer ce contact.

Le num\u00e9ro de t\u00e9l\u00e9phone que vous avez entr\u00e9

est dans un format invalide.
", + "app_phonebook_new_contact_unable_to_save": "Impossible d'enreg. le contact", + "app_phonebook_new_contact_same_numbers": "Malgr\u00e9 l'indicatif du pays saisi, les num\u00e9ros de t\u00e9l\u00e9phone sont les m\u00eames.



Entrez un autre num\u00e9ro pour enregistrer le contact.", "app_phonebook_new_contact_last_name": "Nom", "app_phonebook_new_contact_note": "Note", "app_phonebook_new_contact_number": "Num\u00e9ro", diff --git a/image/system_a/data/lang/Polski.json b/image/system_a/data/lang/Polski.json index 14d38df14ecf86b4c68e6d833c959f2eeb17bc1e..008c86376142f52bd45b004fc8f267223407f571 100644 --- a/image/system_a/data/lang/Polski.json +++ b/image/system_a/data/lang/Polski.json @@ -362,6 +362,8 @@ "app_phonebook_new_contact_email": "E-mail", "app_phonebook_new_contact_first_name": "Imi\u0119", "app_phonebook_new_contact_invalid_number": "Nie mo\u017cna zapisa\u0107 tego kontaktu.

Wprowadzony numer telefonu

ma nieprawid\u0142owy format.
", + "app_phonebook_new_contact_unable_to_save": "Nie mo\u017cna zapisa\u0107 kontaktu", + "app_phonebook_new_contact_same_numbers": "Pomijaj\u0105c numery kierunkowe,

wprowad\u017aone numery s\u0105 takie same.




Wprowad\u017a inne numery

by zapisać kontakt.
", "app_phonebook_new_contact_last_name": "Nazwisko", "app_phonebook_new_contact_note": "Notatka", "app_phonebook_new_contact_number": "Numer", diff --git a/image/system_a/data/lang/Svenska.json b/image/system_a/data/lang/Svenska.json index 2d655f90d56bb875022ebee3ea06668e680113ce..044d042f6c3c7e57d0b3cccb07c9a4f53787066d 100644 --- a/image/system_a/data/lang/Svenska.json +++ b/image/system_a/data/lang/Svenska.json @@ -227,6 +227,8 @@ "app_phonebook_new_contact_email": "Mail", "app_phonebook_new_contact_first_name": "F\u00f6rnamn", "app_phonebook_new_contact_invalid_number": "Det g\u00e5r inte att spara den h\u00e4r kontakten.

Telefonnumret du angav

\u00e4r i ett ogiltigt format.
", + "app_phonebook_new_contact_unable_to_save": "Kan inte spara kontakt", + "app_phonebook_new_contact_same_numbers": "Trots landskoden \u00e4r telefonnumren identiska.



Ange ett annat nummer för att sparakontakten.", "app_phonebook_new_contact_last_name": "Efternamn", "app_phonebook_new_contact_note": "Anteckning", "app_phonebook_new_contact_number": "Nummer", diff --git a/module-apps/application-phonebook/windows/PhonebookNewContact.cpp b/module-apps/application-phonebook/windows/PhonebookNewContact.cpp index 92885afc7a926d77e28d0b73eb1bf4de9cbccd9f..8deb1f55d65292609c3717204bea63161cea4b4f 100644 --- a/module-apps/application-phonebook/windows/PhonebookNewContact.cpp +++ b/module-apps/application-phonebook/windows/PhonebookNewContact.cpp @@ -160,6 +160,9 @@ namespace gui case DBServiceAPI::ContactVerificationResult::secondaryNumberDuplicate: showDialogDuplicatedNumber(contact->numbers[1].number, contact->ID); return false; + case DBServiceAPI::ContactVerificationResult::primaryAndSecondaryNumberAreTheSame: + showDialogPrimaryAndSecondaryNumberAreTheSame(); + return false; case DBServiceAPI::ContactVerificationResult::speedDialDuplicate: showDialogDuplicatedSpeedDialNumber(); return false; @@ -302,4 +305,18 @@ namespace gui contactByID->front().numbers.empty(); } + void PhonebookNewContact::showDialogPrimaryAndSecondaryNumberAreTheSame() + { + auto metaData = std::make_unique( + gui::DialogMetadata{utils::translate("app_phonebook_new_contact_unable_to_save"), + "fail_128px_W_G", + utils::translate("app_phonebook_new_contact_same_numbers"), + "", + [=]() -> bool { + application->returnToPreviousWindow(); + return true; + }}); + + application->switchWindow(gui::window::name::dialog, std::move(metaData)); + } } // namespace gui diff --git a/module-apps/application-phonebook/windows/PhonebookNewContact.hpp b/module-apps/application-phonebook/windows/PhonebookNewContact.hpp index b48dddf53e2bf7b79c09606f3240ca665befd025..1357e790e04f6d74f6bba05733862e8b07110231 100644 --- a/module-apps/application-phonebook/windows/PhonebookNewContact.hpp +++ b/module-apps/application-phonebook/windows/PhonebookNewContact.hpp @@ -38,6 +38,7 @@ namespace gui void showDialogDuplicatedNumber(const utils::PhoneNumber::View &duplicatedNumber, const std::uint32_t duplicatedNumberContactID = 0u); void showDialogDuplicatedSpeedDialNumber(); + void showDialogPrimaryAndSecondaryNumberAreTheSame(); void setSaveButtonVisible(bool visible); void showContactDeletedNotification(); bool checkIfContactWasDeletedDuringEditProcess() const; diff --git a/module-db/Interface/ContactRecord.hpp b/module-db/Interface/ContactRecord.hpp index 064f75c909d35a57f93334813eb09290ce3151a6..6aceb1c37a7577b74241625fdbe6c642ae2c1535 100644 --- a/module-db/Interface/ContactRecord.hpp +++ b/module-db/Interface/ContactRecord.hpp @@ -225,6 +225,8 @@ class ContactRecordInterface : public RecordInterface std::vector; + auto hasContactRecordSameNumbers(const ContactRecord &rec) -> bool; + /** * @brief Merge contacts list with overriding the duplicates in contacts DB * @@ -319,6 +321,4 @@ class ContactRecordInterface : public RecordInterface &oldNumberIDs, std::vector &newNumbers) -> bool; - - auto hasContactRecordSameNumbers(const ContactRecord &rec) -> bool; }; diff --git a/module-services/service-db/DBServiceAPI.cpp b/module-services/service-db/DBServiceAPI.cpp index 1487f0ae034696bbfde7965f0ecc9af7d38ab4ee..8d65259135cc759594337bbae14db9806311ffe1 100644 --- a/module-services/service-db/DBServiceAPI.cpp +++ b/module-services/service-db/DBServiceAPI.cpp @@ -157,6 +157,10 @@ auto DBServiceAPI::verifyContact(sys::Service *serv, const ContactRecord &rec) return ContactVerificationResult::speedDialDuplicate; } + if (rec.numbers.size() >= 2 && hasContactSameNumbers(serv, rec)) { + return ContactVerificationResult::primaryAndSecondaryNumberAreTheSame; + } + if (rec.numbers.size() > 0 && rec.numbers[0].number.getEntered().size() > 0) { auto retPhone1 = MatchContactByPhoneNumber(serv, rec.numbers[0].number, rec.ID); if (retPhone1) { @@ -306,3 +310,22 @@ void DBServiceAPI::InformLanguageChanged(sys::Service *serv) auto query = std::make_unique(); DBServiceAPI::GetQuery(serv, db::Interface::Name::Quotes, std::move(query)); } + +auto DBServiceAPI::hasContactSameNumbers(sys::Service *serv, const ContactRecord &rec) -> bool +{ + std::shared_ptr msg = + std::make_shared(MessageType::DBCheckContactNumbersIsSame, rec); + + auto ret = serv->bus.sendUnicastSync(msg, service::name::db, constants::DefaultTimeoutInMs); + auto contactResponse = dynamic_cast(ret.second.get()); + if (contactResponse == nullptr) { + LOG_ERROR("DB response error, return code: %s", c_str(ret.first)); + return false; // Assumption that the numbers in the contact are not the same + } + if (ret.first == sys::ReturnCodes::Success) { + return contactResponse->retCode; + } + + LOG_ERROR("Checking if contact has same numbers failed"); + return false; // Assumption that the numbers in the contact are not the same +} diff --git a/module-services/service-db/include/service-db/DBServiceAPI.hpp b/module-services/service-db/include/service-db/DBServiceAPI.hpp index 605bb73af9027b886ac68a7ed3dc44c201460a50..38a0c806c1ab5d913f3eb85801124ef28a1e78d8 100644 --- a/module-services/service-db/include/service-db/DBServiceAPI.hpp +++ b/module-services/service-db/include/service-db/DBServiceAPI.hpp @@ -35,13 +35,13 @@ namespace sys class DBServiceAPI { public: - enum class ContactVerificationResult { emptyContact, temporaryContactExists, primaryNumberDuplicate, secondaryNumberDuplicate, + primaryAndSecondaryNumberAreTheSame, speedDialDuplicate, success }; @@ -114,6 +114,8 @@ class DBServiceAPI static auto IsContactInFavourites(sys::Service *serv, const utils::PhoneNumber::View &numberView) -> bool; static auto IsContactInEmergency(sys::Service *serv, const utils::PhoneNumber::View &numberView) -> bool; + + static auto hasContactSameNumbers(sys::Service *serv, const ContactRecord &rec) -> bool; /** * @brief Add sms via DBService interface * diff --git a/products/PurePhone/services/db/ServiceDB.cpp b/products/PurePhone/services/db/ServiceDB.cpp index b548e10348e197bdb4b50fafdc14ca612e92f5a0..32ba5a2925e2dee87a5a739964442f4fde62a0b1 100644 --- a/products/PurePhone/services/db/ServiceDB.cpp +++ b/products/PurePhone/services/db/ServiceDB.cpp @@ -83,10 +83,10 @@ sys::MessagePointer ServiceDB::DataReceivedHandler(sys::DataMessage *msgl, sys:: */ case MessageType::DBContactAdd: { - auto time = utils::time::Scoped("DBContactAdd"); - auto msg = static_cast(msgl); - auto ret = contactRecordInterface->Add(msg->record); - auto record = std::make_unique>(); + auto time = utils::time::Scoped("DBContactAdd"); + auto msg = static_cast(msgl); + auto ret = contactRecordInterface->Add(msg->record); + auto record = std::make_unique>(); record->push_back(msg->record); LOG_DEBUG("Last ID %" PRIu32, msg->record.ID); responseMsg = std::make_shared(std::move(record), ret); @@ -94,21 +94,21 @@ sys::MessagePointer ServiceDB::DataReceivedHandler(sys::DataMessage *msgl, sys:: } break; case MessageType::DBContactGetByID: { - auto time = utils::time::Scoped("DBContactGetByID"); - auto msg = static_cast(msgl); - auto ret = (msg->withTemporary ? contactRecordInterface->GetByIdWithTemporary(msg->record.ID) - : contactRecordInterface->GetByID(msg->record.ID)); - auto records = std::make_unique>(); + auto time = utils::time::Scoped("DBContactGetByID"); + auto msg = static_cast(msgl); + auto ret = (msg->withTemporary ? contactRecordInterface->GetByIdWithTemporary(msg->record.ID) + : contactRecordInterface->GetByID(msg->record.ID)); + auto records = std::make_unique>(); records->push_back(ret); responseMsg = std::make_shared( std::move(records), true, msg->limit, msg->offset, msg->favourite, 1, MessageType::DBContactGetByID); } break; case MessageType::DBContactGetBySpeedDial: { - auto time = utils::time::Scoped("DBContactGetBySpeedDial"); - auto msg = static_cast(msgl); - auto ret = contactRecordInterface->GetBySpeedDial(msg->record.speeddial); - responseMsg = std::make_shared(std::move(ret), + auto time = utils::time::Scoped("DBContactGetBySpeedDial"); + auto msg = static_cast(msgl); + auto ret = contactRecordInterface->GetBySpeedDial(msg->record.speeddial); + responseMsg = std::make_shared(std::move(ret), true, msg->limit, msg->offset, @@ -150,6 +150,15 @@ sys::MessagePointer ServiceDB::DataReceivedHandler(sys::DataMessage *msgl, sys:: } } break; + case MessageType::DBCheckContactNumbersIsSame: { + auto time = utils::time::Scoped("DBCheckContactNumbersIsSame"); + auto msg = static_cast(msgl); + auto ret = contactRecordInterface->hasContactRecordSameNumbers(msg->record); + auto record = std::make_unique>(); + LOG_DEBUG("Has contact same numbers: %d" PRIu32, ret); + responseMsg = std::make_shared(ret, 0, MessageType::MessageTypeUninitialized); + } break; + case MessageType::DBContactMatchByNumberID: { auto time = utils::time::Scoped("DBContactMatchByNumberID"); auto msg = static_cast(msgl); @@ -164,18 +173,18 @@ sys::MessagePointer ServiceDB::DataReceivedHandler(sys::DataMessage *msgl, sys:: } break; case MessageType::DBContactRemove: { - auto time = utils::time::Scoped("DBContactRemove"); - auto msg = static_cast(msgl); - auto ret = contactRecordInterface->RemoveByID(msg->id); - responseMsg = std::make_shared(nullptr, ret); + auto time = utils::time::Scoped("DBContactRemove"); + auto msg = static_cast(msgl); + auto ret = contactRecordInterface->RemoveByID(msg->id); + responseMsg = std::make_shared(nullptr, ret); sendUpdateNotification(db::Interface::Name::Contact, db::Query::Type::Delete, msg->id); } break; case MessageType::DBContactUpdate: { - auto time = utils::time::Scoped("DBContactUpdate"); - auto msg = static_cast(msgl); - auto ret = contactRecordInterface->Update(msg->record); - responseMsg = std::make_shared(nullptr, ret); + auto time = utils::time::Scoped("DBContactUpdate"); + auto msg = static_cast(msgl); + auto ret = contactRecordInterface->Update(msg->record); + responseMsg = std::make_shared(nullptr, ret); sendUpdateNotification(db::Interface::Name::Contact, db::Query::Type::Update, msg->record.ID); } break; @@ -184,11 +193,11 @@ sys::MessagePointer ServiceDB::DataReceivedHandler(sys::DataMessage *msgl, sys:: */ case MessageType::DBCalllogAdd: { - auto time = utils::time::Scoped("DBCalllogAdd"); - auto msg = static_cast(msgl); - auto record = std::make_unique>(); - msg->record.ID = DB_ID_NONE; - auto ret = calllogRecordInterface->Add(msg->record); + auto time = utils::time::Scoped("DBCalllogAdd"); + auto msg = static_cast(msgl); + auto record = std::make_unique>(); + msg->record.ID = DB_ID_NONE; + auto ret = calllogRecordInterface->Add(msg->record); if (ret) { // return the newly added record msg->record = calllogRecordInterface->GetByID(calllogRecordInterface->GetLastID()); @@ -200,18 +209,18 @@ sys::MessagePointer ServiceDB::DataReceivedHandler(sys::DataMessage *msgl, sys:: } break; case MessageType::DBCalllogRemove: { - auto time = utils::time::Scoped("DBCalllogRemove"); - auto msg = static_cast(msgl); - auto ret = calllogRecordInterface->RemoveByID(msg->id); - responseMsg = std::make_shared(nullptr, ret); + auto time = utils::time::Scoped("DBCalllogRemove"); + auto msg = static_cast(msgl); + auto ret = calllogRecordInterface->RemoveByID(msg->id); + responseMsg = std::make_shared(nullptr, ret); sendUpdateNotification(db::Interface::Name::Calllog, db::Query::Type::Delete, msg->id); } break; case MessageType::DBCalllogUpdate: { - auto time = utils::time::Scoped("DBCalllogUpdate"); - auto msg = static_cast(msgl); - auto ret = calllogRecordInterface->Update(msg->record); - responseMsg = std::make_shared(nullptr, ret); + auto time = utils::time::Scoped("DBCalllogUpdate"); + auto msg = static_cast(msgl); + auto ret = calllogRecordInterface->Update(msg->record); + responseMsg = std::make_shared(nullptr, ret); sendUpdateNotification(db::Interface::Name::Calllog, db::Query::Type::Update, msg->record.ID); } break; diff --git a/pure_changelog.md b/pure_changelog.md index bcc2b76789c32de74523a9656232d707fd9781d7..4024fb876b132ba814bf3b1fe32fde7e094c24fd 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -35,6 +35,7 @@ * Fixed missing tethering icon on "Tethering is on" window * Fixed showing "Copy text" option in empty note * Fixed "Copy" option missing from the options list in "New message" window +* Fixed the ability to create a contact with the same primary and secondary phone number, which resulted in mismatching ## [1.7.2 2023-07-28] diff --git a/source/MessageType.hpp b/source/MessageType.hpp index 44437f94a0147b270f01125a67632e63b32a5ce4..6658f94e92bd52316b17cf9e9888f5062d6ec7f0 100644 --- a/source/MessageType.hpp +++ b/source/MessageType.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 @@ -29,9 +29,12 @@ enum class MessageType DBMatchContactNumberBesidesOfContactID [[deprecated]], ///< used to best match with a single contact using a phone number (primary or secondary) ///< but witch omitting specific contact ID - DBContactAdd [[deprecated]], ///< Add contact record - DBContactRemove [[deprecated]], ///< Remove contact remove - DBContactUpdate [[deprecated]], ///< Update contact remove + DBCheckContactNumbersIsSame [[deprecated]], ///< used to check if a contact have 2 or more same numbers according to + ///< internal rules of number the similarity when the numbers are + ///< practically the same e.g. having a country code is only difference + DBContactAdd [[deprecated]], ///< Add contact record + DBContactRemove [[deprecated]], ///< Remove contact remove + DBContactUpdate [[deprecated]], ///< Update contact remove DBQuery,