-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDialogListWindow.hpp
129 lines (107 loc) · 3.49 KB
/
DialogListWindow.hpp
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#pragma once
#include "td/actor/impl/ActorId-decl.h"
#include "td/tl/TlObject.h"
#include "td/utils/Status.h"
#include "td/utils/Variant.h"
#include "windows/Output.hpp"
#include "windows/PadWindow.hpp"
#include "td/generate/auto/td/telegram/td_api.h"
#include "td/generate/auto/td/telegram/td_api.hpp"
#include "TdcursesWindowBase.hpp"
#include "ChatManager.hpp"
#include "CommandLineWindow.hpp"
#include <memory>
namespace tdcurses {
class Tdcurses;
class DialogListWindow
: public windows::PadWindow
, public TdcursesWindowBase {
public:
struct SublistGlobal {
bool operator==(const SublistGlobal &) const {
return true;
}
};
struct SublistArchive {
bool operator==(const SublistArchive &) const {
return true;
}
};
struct SublistSublist {
bool operator==(const SublistSublist &other) const {
return sublist_id_ == other.sublist_id_;
}
td::int32 sublist_id_;
};
struct SublistSearch {
bool operator==(const SublistSearch &other) const {
return search_pattern_ == other.search_pattern_;
}
std::string search_pattern_;
};
using Sublist = td::Variant<SublistGlobal, SublistArchive, SublistSublist, SublistSearch>;
DialogListWindow(Tdcurses *root, td::ActorId<Tdcurses> root_actor) : TdcursesWindowBase(root, std::move(root_actor)) {
set_pad_to(PadTo::Top);
clear();
set_title("global");
}
class Element;
class Element
: public windows::PadWindowElement
, public Chat {
public:
Element(td::tl_object_ptr<td::td_api::chat> chat) : Chat(std::move(chat)) {
}
td::int32 render(windows::PadWindow &root, windows::WindowOutputter &rb, windows::SavedRenderedImagesDirectory &dir,
bool is_selected) override;
bool is_less(const windows::PadWindowElement &elx) const override {
const Element &el = static_cast<const Element &>(elx);
return order_ > el.order_ || (order_ == el.order_ && chat_id() > el.chat_id());
}
bool is_visible() const override {
return order_ != 0;
}
bool is_pinned(const Sublist &cur_sublist);
void update_order(const Sublist &cur_sublist);
void force_update_order(td::int64 order) {
order_ = order;
}
void update_sublist(const Sublist &cur_sublist);
auto cur_order() const {
return order_;
}
private:
td::int64 order_{0};
};
void handle_input(const windows::InputEvent &info) override;
void request_bottom_elements() override;
void received_bottom_elements(td::Result<td::tl_object_ptr<td::td_api::ok>> R);
void received_bottom_chats(td::Result<td::tl_object_ptr<td::td_api::chats>> R);
template <typename T>
void process_update(T &upd) {
chat_manager().process_update(upd);
auto chat = chat_manager().get_chat(upd.chat_id_);
if (chat) {
change_element(static_cast<Element *>(chat.get()));
}
}
template <typename T>
void process_user_update(T &upd) {
chat_manager().process_update(upd);
}
void process_update(td::td_api::updateNewChat &update);
void process_update(td::td_api::updateChatLastMessage &update);
void process_update(td::td_api::updateChatPosition &update);
void set_search_pattern(std::string pattern);
void update_sublist(Sublist new_sublist);
void set_sublist(Sublist new_sublist);
const auto &cur_sublist() const {
return cur_sublist_;
}
void scroll_to_chat(td::int64 chat_id);
private:
bool running_req_{false};
bool is_completed_{false};
Sublist cur_sublist_{SublistGlobal{}};
};
} // namespace tdcurses