~aleteoryx/muditaos

0196754e01e9177543bb83a2bf13c8f08a0d2311 — Maciej-Mudita 2 years ago c5fbf28
[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)
M module-apps/application-messages/ApplicationMessages.cpp => module-apps/application-messages/ApplicationMessages.cpp +38 -4
@@ 23,6 23,7 @@
#include <module-db/queries/messages/sms/QuerySMSRemove.hpp>
#include <module-db/queries/messages/sms/QuerySMSUpdate.hpp>
#include <module-db/queries/messages/threads/QueryThreadGetByID.hpp>
#include <module-db/queries/messages/threads/QueryThreadGetByNumber.hpp>
#include <module-db/queries/messages/threads/QueryThreadRemove.hpp>
#include <module-db/queries/phonebook/QueryContactGetByNumberID.hpp>
#include <module-db/queries/notifications/QueryNotificationsDecrement.hpp>


@@ 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<gui::SwitchData> data)
    {
        if (auto sendRequest = dynamic_cast<SMSSendRequest *>(data.get()); sendRequest != nullptr) {
            const auto phoneNumber = sendRequest->getPhoneNumber();
            auto query             = std::make_unique<db::query::ThreadGetByNumber>(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<db::query::ThreadGetByNumberResult *>(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<SMSThreadData>(std::make_unique<ThreadRecord>(thread));
                    switchData->ignoreCurrentWindowOnStack = true;
                    switchWindow(gui::name::window::thread_view, std::move(switchData));
                }

                return true;
            };

            task->setCallback([callback = std::make_shared<decltype(queryCallback)>(std::move(queryCallback))](
                                  auto response) { return (*callback)(response); });
            task->execute(this, this);
            return actionHandled();
        }
        return actionNotHandled();
    }

} /* namespace app */

M module-apps/application-messages/include/application-messages/ApplicationMessages.hpp => module-apps/application-messages/include/application-messages/ApplicationMessages.hpp +3 -0
@@ 66,6 66,9 @@ namespace app

        // used by sms template items
        std::function<bool(std::shared_ptr<SMSTemplateRecord> templ)> templatesCallback;

      private:
        ActionResult handleCreateSmsAction(std::unique_ptr<gui::SwitchData> data);
    };

    template <>

M pure_changelog.md => pure_changelog.md +1 -0
@@ 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]