~aleteoryx/muditaos

4f7ec2efd387c6195288fa9086069c4b30e37aac — Lukasz Mastalerz 2 years ago 43d3a71
[CP-1831] Editing contact which is deleted via Center can still be saved but with incomplete data

Fix for editing contact when it was deleted via Center.
Edited contact cannot be saved if it was deleted earlier. Proper communication is shown.
Fix for phonebook app was not handling database notifications correctly.
M image/system_a/data/lang/Deutsch.json => image/system_a/data/lang/Deutsch.json +1 -0
@@ 591,6 591,7 @@
  "app_phonebook_uncheck": "AUSWAHL ENTFERNEN",
  "app_phonebook_multiple_numbers_first": "Nummer",
  "app_phonebook_multiple_numbers_second": "Zweite nummer",
  "app_phonebook_contact_deleted": "<text>Der Kontakt wurde gelöscht.<br></br>Die Bearbeitung ist nicht möglich.</text>",
  "app_meditation_title_main": "Meditationstimer",
  "app_meditation_preparation_time": "Vorbereitungstimer",
  "app_meditation_put_down_phone_and_wait": "<text>Legen Sie das Telefon weg<br>und warten Sie auf den Gong.</text>",

M image/system_a/data/lang/English.json => image/system_a/data/lang/English.json +1 -0
@@ 556,6 556,7 @@
  "app_phonebook_uncheck": "UNCHECK",
  "app_phonebook_multiple_numbers_first": "Number",
  "app_phonebook_multiple_numbers_second": "Second number",
  "app_phonebook_contact_deleted": "<text>Contact has been deleted.<br></br>Editing is not possible.</text>",
  "app_meditation_title_main": "Meditation timer",
  "app_meditation_preparation_time": "Preparation time",
  "app_meditation_put_down_phone_and_wait": "<text>Put down the phone<br>and wait for the gong.</text>",

M image/system_a/data/lang/Espanol.json => image/system_a/data/lang/Espanol.json +1 -0
@@ 592,6 592,7 @@
  "app_phonebook_uncheck": "DESMARCAR",
  "app_phonebook_multiple_numbers_first": "Número",
  "app_phonebook_multiple_numbers_second": "Número alternativo",
  "app_phonebook_contact_deleted": "<text>Se ha eliminado el contacto.<br></br>No es posible editar.</text>",
  "app_meditation_title_main": "Temporizador de meditación",
  "app_meditation_preparation_time": "Tiempo de preparación",
  "app_meditation_put_down_phone_and_wait": "<text>Deja a un lado el teléfono<br>y espera a que suene el gong.</text>",

M image/system_a/data/lang/Francais.json => image/system_a/data/lang/Francais.json +1 -0
@@ 560,6 560,7 @@
  "app_phonebook_uncheck": "DÉCOCHER",
  "app_phonebook_multiple_numbers_first": "Numéro",
  "app_phonebook_multiple_numbers_second": "Second numéro",
  "app_phonebook_contact_deleted": "<text>Le contact a été supprimé.<br></br>La modification n'est pas possible.</text>",
  "app_meditation_title_main": "Minuterie de méditation",
  "app_meditation_preparation_time": "Temps de préparation",
  "app_meditation_put_down_phone_and_wait": "<text>Posez le téléphone<br>et attendez le son du gong.</text>",

M image/system_a/data/lang/Polski.json => image/system_a/data/lang/Polski.json +1 -0
@@ 590,6 590,7 @@
  "app_phonebook_uncheck": "ODZNACZ",
  "app_phonebook_multiple_numbers_first": "Numer",
  "app_phonebook_multiple_numbers_second": "Drugi numer",
  "app_phonebook_contact_deleted": "<text>Kontakt został usunięty.<br></br>Brak możliwości edycji.</text>",
  "app_meditation_title_main": "Medytacja",
  "app_meditation_preparation_time": "Czas przygotowania",
  "app_meditation_put_down_phone_and_wait": "<text>Odłóż telefon<br>i zaczekaj na gong.</text>",

M image/system_a/data/lang/Svenska.json => image/system_a/data/lang/Svenska.json +1 -0
@@ 496,6 496,7 @@
  "app_phonebook_uncheck": "AVMARKERA",
  "app_phonebook_multiple_numbers_first": "Nummer",
  "app_phonebook_multiple_numbers_second": "Alternativnummer",
  "app_phonebook_contact_deleted": "<text>Kontakten är raderad;<br></br>den kan inte redigeras.</text>",
  "app_meditation_title_main": "Meditationsklocka",
  "app_meditation_preparation_time": "Förbered dig",
  "app_meditation_put_down_phone_and_wait": "<text>Sätt ner telefonen<br>och vänta på klockslaget.</text>",

M module-apps/application-phonebook/windows/PhonebookContactDetails.cpp => module-apps/application-phonebook/windows/PhonebookContactDetails.cpp +1 -1
@@ 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 "PhonebookContactDetails.hpp"

M module-apps/application-phonebook/windows/PhonebookContactDetails.hpp => module-apps/application-phonebook/windows/PhonebookContactDetails.hpp +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

#pragma once

M module-apps/application-phonebook/windows/PhonebookNewContact.cpp => module-apps/application-phonebook/windows/PhonebookNewContact.cpp +33 -2
@@ 4,6 4,7 @@
#include "PhonebookNewContact.hpp"

#include "DialogMetadata.hpp"
#include "DialogMetadataMessage.hpp"
#include "application-phonebook/ApplicationPhonebook.hpp"

#include <Dialog.hpp>


@@ 177,7 178,6 @@ namespace gui
        else {
            contact->removeFromGroup(ContactsDB::temporaryGroupId());
        }

        // perform actual add/update operation
        if (contactAction == ContactAction::Add) {
            auto returnedContact = DBServiceAPI::ContactAdd(application, *contact);


@@ 189,7 189,12 @@ namespace gui
        }
        else if (contactAction == ContactAction::Edit || contactAction == ContactAction::EditTemporary) {
            contact->groups.erase(ContactsDB::temporaryGroupId());
            if (!DBServiceAPI::ContactUpdate(application, *contact)) {
            if (checkIfContactWasDeletedDuringEditProcess()) {
                LOG_WARN("Contact removed while editing by external resources.");
                showContactDeletedNotification();
                return false;
            }
            else if (!DBServiceAPI::ContactUpdate(application, *contact)) {
                LOG_ERROR("verifyAndSave failed to UPDATE contact");
                return false;
            }


@@ 266,4 271,30 @@ namespace gui
            }});
        application->switchWindow(gui::window::name::dialog_yes_no_icon_txt, std::move(metaData));
    }

    void PhonebookNewContact::showContactDeletedNotification()
    {
        auto icon = "info_128px_W_G";
        auto text = utils::translate("app_phonebook_contact_deleted");

        auto metaData = std::make_unique<gui::DialogMetadataMessage>(gui::DialogMetadata{
            contact->getFormattedName(ContactRecord::NameFormatType::Title), icon, text, "", [=]() -> bool {
                std::unique_ptr<gui::SwitchData> data =
                    std::make_unique<PhonebookItemData>(contact, newContactModel->getRequestType());
                this->application->switchWindow(gui::name::window::main_window, std::move(data));

                return true;
            }});
        application->switchWindow(gui::window::name::dialog_confirm, std::move(metaData));
    }

    bool PhonebookNewContact::checkIfContactWasDeletedDuringEditProcess() const
    {
        const auto contactByID = DBServiceAPI::ContactGetByID(application, contact->ID);

        return contactByID->size() == 1 and contactByID->front().ID == 0 and
               contactByID->front().primaryName.empty() and contactByID->front().alternativeName.empty() and
               contactByID->front().numbers.empty();
    }

} // namespace gui

M module-apps/application-phonebook/windows/PhonebookNewContact.hpp => module-apps/application-phonebook/windows/PhonebookNewContact.hpp +3 -1
@@ 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


@@ 39,6 39,8 @@ namespace gui
                                        const std::uint32_t duplicatedNumberContactID = 0u);
        void showDialogDuplicatedSpeedDialNumber();
        void setSaveButtonVisible(bool visible);
        void showContactDeletedNotification();
        bool checkIfContactWasDeletedDuringEditProcess() const;

        std::shared_ptr<ContactRecord> contact           = nullptr;
        std::shared_ptr<NewContactModel> newContactModel = nullptr;

M module-db/queries/phonebook/QueryContactAdd.cpp => module-db/queries/phonebook/QueryContactAdd.cpp +2 -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 "QueryContactAdd.hpp"


@@ 8,7 8,7 @@

using namespace db::query;

ContactAdd::ContactAdd(const ContactRecord &rec) : Query(Query::Type::Read), rec(rec)
ContactAdd::ContactAdd(const ContactRecord &rec) : Query(Query::Type::Create), rec(rec)
{}

ContactAddResult::ContactAddResult(bool result, unsigned int id, bool duplicated)

M module-db/queries/phonebook/QueryContactRemove.cpp => module-db/queries/phonebook/QueryContactRemove.cpp +2 -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 "QueryContactRemove.hpp"


@@ 7,7 7,7 @@

using namespace db::query;

ContactRemove::ContactRemove(unsigned int id) : Query(Query::Type::Read), id(id)
ContactRemove::ContactRemove(unsigned int id) : Query(Query::Type::Delete), id(id)
{}

ContactRemoveResult::ContactRemoveResult(bool result) : result(result)

M module-db/queries/phonebook/QueryContactUpdate.cpp => module-db/queries/phonebook/QueryContactUpdate.cpp +2 -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 "QueryContactUpdate.hpp"


@@ 8,7 8,7 @@

using namespace db::query;

ContactUpdate::ContactUpdate(const ContactRecord &rec) : Query(Query::Type::Read), rec(std::move(rec))
ContactUpdate::ContactUpdate(const ContactRecord &rec) : Query(Query::Type::Update), rec(std::move(rec))
{}

ContactUpdateResult::ContactUpdateResult(bool result) : result(result)

M pure_changelog.md => pure_changelog.md +2 -0
@@ 88,6 88,8 @@
* Fixed incorrectly displayed Swedish translations in Onboarding
* Fixed going back to wrong window after confirming or cancelling creation of new contact from call log
* Fixed missing "No calls yet" text in call log
* Fixed phonebook is not handling database notification about contacts action done by Center
* Fixed contact deleted via Center cannot be edited by Phonebook app and saved again

## [1.5.0 2022-12-20]