~aleteoryx/muditaos

1ceaffb987b73047213030d8d1ebbb122a035e01 — rrandomsky 2 years ago 1b9fad1
[MOS-925] Fix redirection on BACK from sending message from Contact view

Fix for inconsistent redirection to message threads list when pressing
BACK from sending message from Contact view. Also proveded mechanizm
to help switching back to previous App, when some App call window
from another App.
M module-apps/application-call/windows/CallWindow.cpp => module-apps/application-call/windows/CallWindow.cpp +2 -2
@@ 113,9 113,9 @@ namespace gui
        sendSmsIcon->activatedCallback = [=](gui::Item &item) {
            LOG_INFO("Send message template and reject the call");
            constexpr auto preventAutoLock = true;
            auto msg                       = std::make_unique<SMSSendTemplateRequest>(
                presenter.getPhoneNumber().getView(), preventAutoLock, application->GetName());
            auto msg = std::make_unique<SMSSendTemplateRequest>(presenter.getPhoneNumber().getView(), preventAutoLock);
            msg->ignoreCurrentWindowOnStack = true;
            msg->nameOfSenderApplication    = application->GetName();
            return app::manager::Controller::sendAction(application,
                                                        app::manager::actions::ShowSmsTemplates,
                                                        std::move(msg),

M module-apps/application-messages/ApplicationMessages.cpp => module-apps/application-messages/ApplicationMessages.cpp +1 -0
@@ 452,6 452,7 @@ namespace app
                else {
                    auto switchData = std::make_unique<SMSThreadData>(std::make_unique<ThreadRecord>(thread));
                    switchData->ignoreCurrentWindowOnStack = true;
                    switchData->nameOfSenderApplication    = capturedData->nameOfSenderApplication;
                    switchWindow(gui::name::window::thread_view, std::move(switchData));
                }


M module-apps/application-messages/data/SMSdata.hpp => module-apps/application-messages/data/SMSdata.hpp +2 -10
@@ 72,10 72,8 @@ class SMSSendRequest : public SMSRequest
class SMSSendTemplateRequest : public SMSRequest
{
  public:
    explicit SMSSendTemplateRequest(const utils::PhoneNumber::View &phoneNumber,
                                    bool preventAutoLock                                = false,
                                    std::optional<app::ApplicationName> nameOfSenderApp = std::nullopt)
        : SMSRequest(phoneNumber), preventAutoLock(preventAutoLock), nameOfSenderApp(nameOfSenderApp)
    explicit SMSSendTemplateRequest(const utils::PhoneNumber::View &phoneNumber, bool preventAutoLock = false)
        : SMSRequest(phoneNumber), preventAutoLock(preventAutoLock)
    {}
    ~SMSSendTemplateRequest() override = default;



@@ 84,14 82,8 @@ class SMSSendTemplateRequest : public SMSRequest
        return preventAutoLock;
    }

    [[nodiscard]] auto getNameOfSenderApp() const -> std::optional<app::ApplicationName>
    {
        return nameOfSenderApp;
    }

  private:
    bool preventAutoLock;
    std::optional<app::ApplicationName> nameOfSenderApp;
};

class SMSTemplateSent : public gui::SwitchData

M module-apps/application-messages/windows/NewMessage.cpp => module-apps/application-messages/windows/NewMessage.cpp +10 -1
@@ 59,7 59,13 @@ namespace gui

    bool NewMessageWindow::onInput(const InputEvent &inputEvent)
    {
        return AppWindow::onInput(inputEvent);
        if (!inputEvent.isShortRelease(KeyCode::KEY_RF) || !shouldCurrentAppBeIgnoredOnSwitchBack()) {
            return AppWindow::onInput(inputEvent);
        }

        return app::manager::Controller::switchBack(
            application,
            std::make_unique<app::manager::SwitchBackRequest>(nameOfPreviousApplication.value(), nullptr, true));
    }

    void NewMessageWindow::onBeforeShow(ShowMode mode, SwitchData *data)


@@ 71,6 77,7 @@ namespace gui

        if (auto searchRequest = dynamic_cast<PhonebookSearchRequest *>(data); searchRequest != nullptr) {
            LOG_INFO("Received search results");
            saveInfoAboutPreviousAppForProperSwitchBack(data);
            contact        = searchRequest->result;
            selectedNumber = searchRequest->selectedNumber;
            recipient->setText(contact->getFormattedName());


@@ 88,6 95,7 @@ namespace gui
        }
        else if (auto sendRequest = dynamic_cast<SMSSendRequest *>(data); sendRequest != nullptr) {
            LOG_INFO("Received sms send request");
            saveInfoAboutPreviousAppForProperSwitchBack(data);
            phoneNumber = sendRequest->getPhoneNumber();
            contact     = DBServiceAPI::MatchContactByPhoneNumber(application, phoneNumber);
            if (!contact || contact->isTemporary()) {


@@ 158,6 166,7 @@ namespace gui
            const auto &thread = result->getThread();
            auto switchData    = std::make_unique<SMSThreadData>(std::make_unique<ThreadRecord>(thread));
            switchData->ignoreCurrentWindowOnStack = true;
            switchData->nameOfSenderApplication    = nameOfPreviousApplication;
            application->switchWindow(gui::name::window::thread_view, std::move(switchData));
            return true;
        });

M module-apps/application-messages/windows/NewMessage.hpp => module-apps/application-messages/windows/NewMessage.hpp +4 -2
@@ 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


@@ 15,7 15,9 @@

namespace gui
{
    class NewMessageWindow : public AppWindow, public app::AsyncCallbackReceiver
    class NewMessageWindow : public AppWindow,
                             public app::AsyncCallbackReceiver,
                             public gui::InfoAboutPreviousAppWhereWeComeFrom
    {
      public:
        explicit NewMessageWindow(app::ApplicationCommon *app);

M module-apps/application-messages/windows/SMSTemplatesWindow.cpp => module-apps/application-messages/windows/SMSTemplatesWindow.cpp +4 -5
@@ 113,20 113,19 @@ namespace gui
        }

        if (auto switchData = dynamic_cast<SMSSendTemplateRequest *>(data); switchData != nullptr) {
            ignoreWindowsOfThisAppOnSwitchBack = data->ignoreCurrentWindowOnStack;
            appNameToSwitchBack                = switchData->getNameOfSenderApp();
            saveInfoAboutPreviousAppForProperSwitchBack(data);
            smsSendTemplateRequestHandler(switchData);
        }
    }

    bool SMSTemplatesWindow::onInput(const InputEvent &inputEvent)
    {
        if (!inputEvent.isShortRelease(KeyCode::KEY_RF) || !ignoreWindowsOfThisAppOnSwitchBack ||
            !appNameToSwitchBack.has_value()) {
        if (!inputEvent.isShortRelease(KeyCode::KEY_RF) || !shouldCurrentAppBeIgnoredOnSwitchBack()) {
            return AppWindow::onInput(inputEvent);
        }

        return app::manager::Controller::switchBack(
            application, std::make_unique<app::manager::SwitchBackRequest>(appNameToSwitchBack.value(), nullptr, true));
            application,
            std::make_unique<app::manager::SwitchBackRequest>(nameOfPreviousApplication.value(), nullptr, true));
    }
} /* namespace gui */

M module-apps/application-messages/windows/SMSTemplatesWindow.hpp => module-apps/application-messages/windows/SMSTemplatesWindow.hpp +3 -5
@@ 14,13 14,11 @@

namespace gui
{
    class SMSTemplatesWindow : public AppWindow
    class SMSTemplatesWindow : public AppWindow, public InfoAboutPreviousAppWhereWeComeFrom
    {
        std::shared_ptr<SMSTemplateModel> smsTemplateModel;
        gui::ListView *list                                     = nullptr;
        gui::Icon *emptyListIcon                                = nullptr;
        bool ignoreWindowsOfThisAppOnSwitchBack                 = false;
        std::optional<app::ApplicationName> appNameToSwitchBack = std::nullopt;
        gui::ListView *list      = nullptr;
        gui::Icon *emptyListIcon = nullptr;

        void smsSendTemplateRequestHandler(const SMSSendTemplateRequest *const switchData);
        void smsTemplateRequestHandler(const SMSTemplateRequest *const switchData);

M module-apps/application-messages/windows/SMSThreadViewWindow.cpp => module-apps/application-messages/windows/SMSThreadViewWindow.cpp +7 -0
@@ 5,6 5,7 @@
#include "MessagesStyle.hpp"
#include "SMSdata.hpp"
#include "SMSThreadViewWindow.hpp"
#include "service-appmgr/Controller.hpp"

#include <log/log.hpp>
#include <module-db/queries/notifications/QueryNotificationsDecrement.hpp>


@@ 65,6 66,7 @@ namespace gui
    {
        if (auto pdata = dynamic_cast<SMSThreadData *>(data); pdata) {
            LOG_INFO("Thread data received: %" PRIu32, pdata->thread->ID);
            saveInfoAboutPreviousAppForProperSwitchBack(data);
            requestContact(pdata->thread->numberID);

            // Mark thread as Read


@@ 102,6 104,11 @@ namespace gui
        }
        if (inputEvent.isShortRelease(KeyCode::KEY_RF)) {
            onClose(CloseReason::WindowSwitch);
            if (shouldCurrentAppBeIgnoredOnSwitchBack()) {
                return app::manager::Controller::switchBack(application,
                                                            std::make_unique<app::manager::SwitchBackRequest>(
                                                                nameOfPreviousApplication.value(), nullptr, true));
            }
        }
        return AppWindow::onInput(inputEvent);
    }

M module-apps/application-messages/windows/SMSThreadViewWindow.hpp => module-apps/application-messages/windows/SMSThreadViewWindow.hpp +4 -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

#pragma once


@@ 14,7 14,9 @@

namespace gui
{
    class SMSThreadViewWindow : public AppWindow, public app::AsyncCallbackReceiver
    class SMSThreadViewWindow : public AppWindow,
                                public app::AsyncCallbackReceiver,
                                public gui::InfoAboutPreviousAppWhereWeComeFrom
    {
      private:
        std::shared_ptr<SMSThreadModel> smsModel;

M module-apps/application-phonebook/models/ContactDetailsModel.cpp => module-apps/application-phonebook/models/ContactDetailsModel.cpp +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

#include "ContactDetailsModel.hpp"

M module-apps/application-phonebook/widgets/InformationWidget.cpp => module-apps/application-phonebook/widgets/InformationWidget.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 "InformationWidget.hpp"

M module-apps/apps-common/widgets/ActiveIconFactory.cpp => module-apps/apps-common/widgets/ActiveIconFactory.cpp +2 -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

#include "ActiveIconFactory.hpp"


@@ 45,6 45,7 @@ auto ActiveIconFactory::makeSMSIcon(const utils::PhoneNumber::View &number) -> I
        [application = app, number](gui::Item &item) {
            auto data                        = std::make_unique<SMSSendRequest>(number, std::string{});
            data->ignoreCurrentWindowOnStack = true;
            data->nameOfSenderApplication    = application->GetName();
            return app::manager::Controller::sendAction(application,
                                                        app::manager::actions::CreateSms,
                                                        std::move(data),

M module-gui/gui/SwitchData.hpp => module-gui/gui/SwitchData.hpp +29 -1
@@ 1,12 1,15 @@
// 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

#include <string>
#include <optional>
#include <log/log.hpp>

namespace gui
{
    using NameOfApplication = std::optional<std::string>;

    /// base class storing information sent along with switch message
    /// for extended use with windows please inherit from this class to extend it


@@ 45,6 48,9 @@ namespace gui
        /// requesting getting back in WinC will result in:
        /// `WinC => WinA`
        bool ignoreCurrentWindowOnStack = false;
        /// This can store name of Application when message came from
        /// This is helpful when going back to the previous Application (sender Application)
        NameOfApplication nameOfSenderApplication = std::nullopt;
    };

    class SwitchSpecialChar : public SwitchData


@@ 62,4 68,26 @@ namespace gui
        virtual ~SwitchSpecialChar() = default;
    };

    /// class storing information for Window type class to switch bask to proper Application
    struct InfoAboutPreviousAppWhereWeComeFrom
    {
        NameOfApplication nameOfPreviousApplication = std::nullopt;
        bool ignoreCurrentApplicationOnSwitchBack   = false;

        // save info about Application where we come from and if we should switch back to this Application
        void saveInfoAboutPreviousAppForProperSwitchBack(const SwitchData *memo)
        {
            if (memo == nullptr) {
                LOG_ERROR("Empty pointer to SwitchData");
                return;
            }
            nameOfPreviousApplication            = memo->nameOfSenderApplication;
            ignoreCurrentApplicationOnSwitchBack = memo->ignoreCurrentWindowOnStack;
        }
        bool shouldCurrentAppBeIgnoredOnSwitchBack()
        {
            return ignoreCurrentApplicationOnSwitchBack && nameOfPreviousApplication.has_value();
        }
    };

} /* namespace gui */

M pure_changelog.md => pure_changelog.md +1 -0
@@ 71,6 71,7 @@
* Fixed misleading labels in the Phonebook application when using search engine
* Fixed text pasting in new contact window when some text is already present there
* Fixed unnecessary deep refresh when pressing up arrow in empty list view
* Fixed going back to Messages instead of Contacts in case message thread was previously opened from Contacts

## [1.6.0 2023-02-27]