From 2a901acf0b4e8e40d69d3f22f2bc91dac405174c Mon Sep 17 00:00:00 2001 From: Lefucjusz Date: Mon, 20 Mar 2023 17:24:43 +0100 Subject: [PATCH] [MOS-962] Fix forwarded message automatic pasting Fix of the issue that entering 'Options' menu after forwarding message caused the content of the message to be pasted into message field in thread view. Minor cleanup. --- .../models/SMSThreadModel.cpp | 2 +- .../windows/NewMessage.cpp | 16 +++++---- .../windows/SMSThreadViewWindow.cpp | 33 ++++++++----------- .../apps-common/windows/OptionWindow.cpp | 5 ++- pure_changelog.md | 3 +- 5 files changed, 28 insertions(+), 31 deletions(-) diff --git a/module-apps/application-messages/models/SMSThreadModel.cpp b/module-apps/application-messages/models/SMSThreadModel.cpp index e6655ee67..764f7c6d3 100644 --- a/module-apps/application-messages/models/SMSThreadModel.cpp +++ b/module-apps/application-messages/models/SMSThreadModel.cpp @@ -33,7 +33,7 @@ unsigned int SMSThreadModel::getMinimalItemSpaceRequired() const gui::ListItem *SMSThreadModel::getItem(gui::Order order) { - std::shared_ptr sms = getRecord(order); + const auto sms = getRecord(order); if (sms == nullptr) { return nullptr; diff --git a/module-apps/application-messages/windows/NewMessage.cpp b/module-apps/application-messages/windows/NewMessage.cpp index d940429c9..c9df71161 100644 --- a/module-apps/application-messages/windows/NewMessage.cpp +++ b/module-apps/application-messages/windows/NewMessage.cpp @@ -30,18 +30,20 @@ namespace gui state = std::make_unique(_state->backupText()); } - void getState(gui::Text *_state) + void restoreState(gui::Text *_state) { assert(_state); - if (!state) { + if (state == nullptr) { return; } - auto currentText = _state->getText(); + + const auto currentText = _state->getText(); _state->restoreFrom(*state); if (!currentText.empty()) { _state->addText(currentText); } - state = nullptr; + + state.reset(); } private: @@ -70,7 +72,7 @@ namespace gui void NewMessageWindow::onBeforeShow(ShowMode mode, SwitchData *data) { - memento->getState(message); + memento->restoreState(message); if (data == nullptr) { return; } @@ -139,7 +141,7 @@ namespace gui auto NewMessageWindow::getPhoneNumber() const -> utils::PhoneNumber { if (phoneNumber.getEntered().empty()) { - if (contact && !(contact->numbers.empty())) { + if (contact && !contact->numbers.empty()) { return contact->numbers.at(selectedNumber).number; } return utils::PhoneNumber{recipient->getText()}; @@ -315,7 +317,7 @@ namespace gui return; } - if ((reason == CloseReason::PhoneLock) || (reason == CloseReason::Popup)) { + if (reason != CloseReason::ApplicationClose) { memento->setState(message); message->clear(); return; diff --git a/module-apps/application-messages/windows/SMSThreadViewWindow.cpp b/module-apps/application-messages/windows/SMSThreadViewWindow.cpp index 355f5963a..f5f61dc6c 100644 --- a/module-apps/application-messages/windows/SMSThreadViewWindow.cpp +++ b/module-apps/application-messages/windows/SMSThreadViewWindow.cpp @@ -8,12 +8,9 @@ #include "service-appmgr/Controller.hpp" #include -#include #include #include -#include #include -#include #include #include #include @@ -85,11 +82,14 @@ namespace gui requestContact(smsModel->numberID); } - if (auto pdata = dynamic_cast(data); pdata) { - auto txt = pdata->text; + if (const auto pdata = dynamic_cast(data); pdata != nullptr) { LOG_INFO("received sms templates data"); - pdata->concatenate == SMSTextData::Concatenate::True ? smsModel->smsInput->inputText->addText(txt) - : smsModel->smsInput->inputText->setText(txt); + if (pdata->concatenate == SMSTextData::Concatenate::True) { + smsModel->smsInput->inputText->addText(pdata->text); + } + else { + smsModel->smsInput->inputText->setText(pdata->text); + } } } @@ -120,20 +120,15 @@ namespace gui bool SMSThreadViewWindow::onDatabaseMessage(sys::Message *msgl) { - auto msg = dynamic_cast(msgl); + const auto msg = dynamic_cast(msgl); if (msg != nullptr) { - if (msg->interface == db::Interface::Name::SMS) { - if (msg->dataModified()) { - rebuild(); - return true; - } + if ((msg->interface == db::Interface::Name::SMS) && msg->dataModified()) { + rebuild(); + return true; } - if (msg->interface == db::Interface::Name::SMSThread) { - if (msg->type == db::Query::Type::Delete) { - if (this == application->getCurrentWindow()) { - application->switchWindow(gui::name::window::main_window); - } - } + if ((msg->interface == db::Interface::Name::SMSThread) && (msg->type == db::Query::Type::Delete) && + (this == application->getCurrentWindow())) { + application->switchWindow(gui::name::window::main_window); } } return false; diff --git a/module-apps/apps-common/windows/OptionWindow.cpp b/module-apps/apps-common/windows/OptionWindow.cpp index 523a950e6..9b7a7086f 100644 --- a/module-apps/apps-common/windows/OptionWindow.cpp +++ b/module-apps/apps-common/windows/OptionWindow.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 "OptionWindow.hpp" @@ -60,8 +60,7 @@ namespace gui void OptionWindow::onBeforeShow(ShowMode mode, SwitchData *data) { - if (auto message = dynamic_cast(data)) { - LOG_DEBUG("Options load!"); + if (const auto message = dynamic_cast(data); message != nullptr) { options = message->takeOptions(); } diff --git a/pure_changelog.md b/pure_changelog.md index f4c47d3dc..2a7dcee8e 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -75,7 +75,8 @@ * Fixed going back to Messages instead of Contacts in case message thread was previously opened from Contacts * Fixed autoconnecting other BT devices when another one is already connected * Fixed going to Calls instead of Contacts after aborted or confirmed attempt to create contact from Calls -* Fix misleading "Nie" abbreviation for word "Niedziela" (Sunday) in new alarm window +* Fixed misleading "Nie" abbreviation for word "Niedziela" (Sunday) in new alarm window +* Fixed automatic message pasting into content field in thread view after message forwarding ## [1.6.0 2023-02-27]