~aleteoryx/muditaos

muditaos/module-apps/application-messages/windows/NewMessage.hpp -rw-r--r-- 2.3 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

#include <chrono>
#include <string>

#include <AsyncTask.hpp>
#include <AppWindow.hpp>
#include <PhoneNumber.hpp>
#include <widgets/text/Text.hpp>
#include <module-db/Interface/SMSRecord.hpp>
#include <module-db/Interface/ContactRecord.hpp>

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

        bool onInput(const InputEvent &inputEvent) override;
        void onBeforeShow(ShowMode mode, SwitchData *data) override;
        void buildInterface() override;
        void onClose(CloseReason reason) override;

      private:
        bool selectContact();
        bool sendSms();
        bool switchToThreadWindow(const utils::PhoneNumber::View &number);
        void updateNavBar();
        auto getPhoneNumber() const -> utils::PhoneNumber;
        auto handleMessageText() -> bool;
        auto addDraft(const utils::PhoneNumber &number) -> bool;
        auto addDraftToExistingThread(unsigned int threadId, const utils::PhoneNumber::View &number, const UTF8 &text)
            -> bool;
        void storeMessageDraft(const utils::PhoneNumber::View &number, const UTF8 &text);
        void storeMessageDraft(SMSRecord &sms, const UTF8 &text);
        gui::Text *recipient = nullptr;
        gui::Text *message   = nullptr;
        gui::VBox *body      = nullptr;
        std::shared_ptr<ContactRecord> contact;
        utils::PhoneNumber::View phoneNumber;
        unsigned int selectedNumber = 0;

        /// MessageMemento class provides buffer-like functionality for message field of NewMessageWindow.
        /// MessageMemento shall be used whenever there is a need for temporary window switch in normal (uninterrupted)
        /// flow of new message preparation, such as using options or recipient selection.
        class MessageMemento;
        static std::unique_ptr<MessageMemento> mementoMessage;
        static std::unique_ptr<MessageMemento> mementoRecipient;
    };
} /* namespace gui */