From d84671140f8915ab221eed4462dee5be84be6b49 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 1826689c2e69618e98843d0ad0b9ae908ccc8492..660e6cb98594237a654a516f44b2db6092e3915d 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 1f632fc5ab6314c8db22de27dba0a477dced1a03..520def25c8bc53cc5233ed4446a62cccc75dab18 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 fda26f1139be7c1bb43307fe1ba3c4a9d51a1b1c..c63f8579abc4ff9ede27b2636aae28e187f940b4 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 52880199b3f41be87e99206288cebc2ebf4679da..a78e035f4241462470cb8b5d9c5c6c3f0ad8ded5 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 bd31fe51fcbfe9aece7fbb645cffd844cccd28ef..54ffa46b1fcafa440ad80712af1055aa8719be88 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 4f30316d7355a1e1e16db9dae573ceee2ec201cb..c019723c92a212f10009ec7f4c4e3247ab4f3421 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 188e7fdbbdffb717e82ccd53355449d1d980d7e8..fc0c44bcea54fbbc213d0a4ba9b0df0cd7b205e0 100644 --- a/module-apps/application-phonebook/windows/PhonebookNewContact.cpp +++ b/module-apps/application-phonebook/windows/PhonebookNewContact.cpp @@ -193,6 +193,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; @@ -338,4 +341,18 @@ namespace gui return newContactModel->isAnyUnsavedChange(contact); } + 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 3cd59a53d1e55f7d3ccc8e117a2c0c94488640a8..7c7d834e73819ece72d19c785f1a86613ca31983 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 showDialogUnsavedChanges(std::function whereToGoOnYes = nullptr); void setSaveButtonVisible(bool visible); void showContactDeletedNotification(); 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 6d84779c0751196d4b9f92229f29974db5c51ccc..afc4a620c2c2a695a2a18c081936b95911a9f0ab 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -40,6 +40,7 @@ * Fixed losing unsaved data on go back * Fixed disabled screen autolock in meditation app * Fixed multiple issues with input fields in "New alarm" 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,