~aleteoryx/muditaos

ref: 2cff347326ffc377a227b3a28faa009be8a6a1e0 muditaos/module-apps/application-messages/windows/SMSThreadViewWindow.hpp -rw-r--r-- 2.9 KiB
2cff3473 — Marcin Smoczyński [EGD-4002] audio: remove phone call recording (#794) 5 years 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once

#include <AppWindow.hpp>
#include <application-messages/widgets/SMSInputWidget.hpp>
#include <gui/widgets/BoxLayout.hpp>
#include <gui/widgets/Image.hpp>
#include <gui/widgets/Label.hpp>
#include <gui/widgets/Window.hpp>
#include <ListView.hpp>
#include <PhoneNumber.hpp>
#include <service-db/api/DBServiceAPI.hpp>
#include <Text.hpp>

#include <functional>
#include <string>

namespace gui
{
    class SMSThreadViewWindow : public AppWindow
    {
      private:
        gui::VBox *body         = nullptr;
        uint16_t elements_width = this->getWidth() - style::window::default_left_margin * 2;
        void cleanView();
        enum class Action
        {
            Init,        /// first load of sms thread view
            NewestPage,  /// show a sms thread page from the latest sms
            Refresh,     /// just refresh current view
            NextPage,    /// load previous page
            PreviousPage /// load next page
        };
        /// return if request was handled
        bool showMessages(Action what);
        void addSMS(Action what);
        bool smsBuild(const SMSRecord &smsRecord);
        Label *timeLabelBuild(time_t timestamp) const;
        HBox *smsSpanBuild(Text *smsBubble, const SMSRecord &el) const;
        const ssize_t maxsmsinwindow = 7;

        std::shared_ptr<ContactRecord> contact;
        std::unique_ptr<utils::PhoneNumber::View> number;

        struct
        {
            int start  = 0;                              // actual shown position start
            int end    = 7;                              // actual shown position end
            int thread = 0;                              // thread we are showing
            int dbsize = 0;                              // size of elements in db
            std::unique_ptr<std::vector<SMSRecord>> sms; // loaded sms from db
            std::optional<SMSRecord> draft;              // draft message of the thread we are showing, if exists.
        } SMS;

        gui::SMSInputWidget *inputMessage                 = nullptr;
        inline static const std::uint32_t numberIdTimeout = 1000;

      public:
        SMSThreadViewWindow(app::Application *app);

        virtual ~SMSThreadViewWindow();
        // virtual methods
        bool onInput(const InputEvent &inputEvent) override;

        void onBeforeShow(ShowMode mode, SwitchData *data) override;
        void onClose() override;

        bool onDatabaseMessage(sys::Message *msgl) override;
        void rebuild() override;
        void buildInterface() override;

        void destroyInterface() override;
        void destroyTextItem();
        void refreshTextItem();
        void addTimeLabel(HBox *layout, Label *timeLabel, uint16_t widthAvailable) const;
        void addErrorIcon(HBox *layout) const;

        void handleDraftMessage();
        void clearDraftMessage();
        void updateDraftMessage(const UTF8 &inputText);
        void displayDraftMessage() const;
    };

} /* namespace gui */