From 0196754e01e9177543bb83a2bf13c8f08a0d2311 Mon Sep 17 00:00:00 2001 From: Maciej-Mudita Date: Wed, 15 Feb 2023 13:49:37 +0100 Subject: [PATCH] [MOS-38] Fix window redirection when clicking on the SMS icon After clicking the message icon on the "contact details" screen, the user will be redirected to either the message thread with that person or to the new message screen (only if thread does not exist yet / or has been deleted in the past) --- .../ApplicationMessages.cpp | 42 +++++++++++++++++-- .../ApplicationMessages.hpp | 3 ++ pure_changelog.md | 1 + 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/module-apps/application-messages/ApplicationMessages.cpp b/module-apps/application-messages/ApplicationMessages.cpp index a062218a02e95920e54a2b4dde60d9f0ef153f2a..06b12f9ee0de77b0fc8d6faa0082da21f80c3cda 100644 --- a/module-apps/application-messages/ApplicationMessages.cpp +++ b/module-apps/application-messages/ApplicationMessages.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -49,10 +50,8 @@ namespace app AsyncCallbackReceiver{this} { bus.channels.push_back(sys::BusChannel::ServiceDBNotifications); - addActionReceiver(manager::actions::CreateSms, [this](auto &&data) { - switchWindow(gui::name::window::new_sms, std::move(data)); - return actionHandled(); - }); + addActionReceiver(manager::actions::CreateSms, + [this](auto &&data) { return handleCreateSmsAction(std::move(data)); }); addActionReceiver(manager::actions::ShowSmsTemplates, [this](auto &&data) { switchWindow(gui::name::window::sms_templates, std::move(data)); return actionHandled(); @@ -435,4 +434,39 @@ namespace app return true; } + ActionResult ApplicationMessages::handleCreateSmsAction(std::unique_ptr data) + { + if (auto sendRequest = dynamic_cast(data.get()); sendRequest != nullptr) { + const auto phoneNumber = sendRequest->getPhoneNumber(); + auto query = std::make_unique(phoneNumber); + auto task = app::AsyncQuery::createFromQuery(std::move(query), db::Interface::Name::SMSThread); + + auto queryCallback = [this, capturedData = std::move(data)](auto response) mutable { + const auto result = dynamic_cast(response); + if (result == nullptr) { + switchWindow(gui::name::window::new_sms, std::move(capturedData)); + return false; + } + + const auto &thread = result->getThread(); + if (!thread.isValid()) { + switchWindow(gui::name::window::new_sms, std::move(capturedData)); + } + else { + auto switchData = std::make_unique(std::make_unique(thread)); + switchData->ignoreCurrentWindowOnStack = true; + switchWindow(gui::name::window::thread_view, std::move(switchData)); + } + + return true; + }; + + task->setCallback([callback = std::make_shared(std::move(queryCallback))]( + auto response) { return (*callback)(response); }); + task->execute(this, this); + return actionHandled(); + } + return actionNotHandled(); + } + } /* namespace app */ diff --git a/module-apps/application-messages/include/application-messages/ApplicationMessages.hpp b/module-apps/application-messages/include/application-messages/ApplicationMessages.hpp index 8ed34dd384ea95ea4d7ee377c191e3a7828cf52e..be2b22b0b3e85ff24b70997a19ab0cc275c23b02 100644 --- a/module-apps/application-messages/include/application-messages/ApplicationMessages.hpp +++ b/module-apps/application-messages/include/application-messages/ApplicationMessages.hpp @@ -66,6 +66,9 @@ namespace app // used by sms template items std::function templ)> templatesCallback; + + private: + ActionResult handleCreateSmsAction(std::unique_ptr data); }; template <> diff --git a/pure_changelog.md b/pure_changelog.md index f2112b5e240cf2398217a90fca1074778cfa2289..954f4e56b8a4d57061d6fc032fea63c134fe84ce 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -77,6 +77,7 @@ * Fixed displaying usual SMS template call rejection window when no templates were defined * Fixed going back to wrong window after confirming or cancelling creation of new contact from call log * Fixed misleading popup on SMS send when modem is rebooting +* Fixed window redirection when clicking SMS icon ## [1.5.0 2022-12-20]