-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGlobalParameters.hpp
288 lines (234 loc) · 8.97 KB
/
GlobalParameters.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#pragma once
#include "auto/td/telegram/td_api.h"
#include "auto/td/telegram/td_api.hpp"
#include "td/tl/TlObject.h"
#include "td/utils/Slice-decl.h"
#include "td/utils/common.h"
#include "td/utils/overloaded.h"
#include "td/utils/port/Stat.h"
#include "windows/Markup.hpp"
#include "windows/Output.hpp"
#include <map>
#include <array>
#include <vector>
namespace tdcurses {
enum NotificationScope : td::uint32 {
NotificationScopePrivateChats = 0,
NotificationScopeGroupChats = 1,
NotificationScopeChannelChats = 2,
NotificationScopeCount = 3
};
class GlobalParameters {
public:
std::string version() const {
return "0.4.0";
}
void process_update(td::td_api::updateScopeNotificationSettings &update) {
td::uint32 scope = 0;
td::td_api::downcast_call(
*update.scope_,
td::overloaded(
[&](td::td_api::notificationSettingsScopePrivateChats &) { scope = NotificationScopePrivateChats; },
[&](td::td_api::notificationSettingsScopeGroupChats &) { scope = NotificationScopeGroupChats; },
[&](td::td_api::notificationSettingsScopeChannelChats &) { scope = NotificationScopeChannelChats; }));
scope_notification_settings_[scope] = std::move(update.notification_settings_);
}
void process_update(td::td_api::updateReactionNotificationSettings &update) {
}
void process_update(td::td_api::updateChatFolders &update) {
chat_folders_ = std::move(update.chat_folders_);
}
void process_update(td::td_api::updateFileDownloads &update) {
download_list_bytes_ = update.total_size_;
download_list_files_ = update.total_count_;
downloaded_bytes_ = update.downloaded_size_;
}
void process_update(td::td_api::updateUserPrivacySettingRules &update) {
}
void process_update(td::td_api::updateSavedAnimations &update) {
saved_animations_ = std::move(update.animation_ids_);
}
void process_update(td::td_api::updateDefaultBackground &update) {
(update.for_dark_theme_ ? default_dark_background_ : default_light_background_) = std::move(update.background_);
}
void process_update(td::td_api::updateChatThemes &update) {
chat_themes_ = std::move(update.chat_themes_);
}
void process_update(td::td_api::updateAccentColors &update) {
std::map<td::int32, td::tl_object_ptr<td::td_api::accentColor>> n;
for (auto &x : update.colors_) {
auto id = x->id_;
n[id] = std::move(x);
}
accent_colors_ = std::move(n);
available_accent_color_ids_ = std::move(update.available_accent_color_ids_);
}
void process_update(td::td_api::updateProfileAccentColors &update) {
profile_accent_colors_ = std::move(update.colors_);
profile_available_accent_color_ids_ = std::move(update.available_accent_color_ids_);
}
void process_update(td::td_api::updateLanguagePackStrings &update) {
}
void process_update(td::td_api::updateConnectionState &update) {
connection_state_ = std::move(update.state_);
}
void process_update(td::td_api::updateAttachmentMenuBots &update) {
attachment_menu_bots_ = std::move(update.bots_);
}
void process_update(td::td_api::updateActiveEmojiReactions &update) {
active_emoji_reactions_ = std::move(update.emojis_);
}
void process_update(td::td_api::updateAvailableMessageEffects &update) {
avaliable_message_reaction_effect_ids_ = std::move(update.reaction_effect_ids_);
avaliable_message_sticker_effect_ids_ = std::move(update.sticker_effect_ids_);
}
void process_update(td::td_api::updateDefaultReactionType &update) {
default_reaction_type_ = std::move(update.reaction_type_);
}
void process_update(td::td_api::updateOwnedStarCount &update) {
stars_owned_ = std::move(update.star_amount_);
}
void process_update(td::td_api::updateDiceEmojis &update) {
dice_emojis_ = std::move(update.emojis_);
}
void process_update(td::td_api::updateAnimationSearchParameters &update) {
animation_search_provider_ = std::move(update.provider_);
animation_search_suggested_emojis_ = std::move(update.emojis_);
}
void process_update(td::td_api::updateAutosaveSettings &update) {
}
const auto &chat_folders() const {
return chat_folders_;
}
auto download_list_bytes() const {
return download_list_bytes_;
}
auto download_list_files() const {
return download_list_files_;
}
auto downloaded_bytes() const {
return downloaded_bytes_;
}
const auto &stars_owned() const {
return stars_owned_;
}
const auto &connection_state() const {
return connection_state_;
}
void set_copy_command(std::string command) {
copy_command_ = std::move(command);
}
const auto ©_command() const {
return copy_command_;
}
void set_link_open_command(std::string command) {
link_open_command_ = std::move(command);
}
const auto &link_open_command() const {
return link_open_command_;
}
void set_file_open_command(std::string command) {
file_open_command_ = std::move(command);
}
const auto &file_open_command() const {
return file_open_command_;
}
void update_my_user_id(td::int64 id) {
my_user_id_ = id;
}
td::int64 my_user_id() const {
return my_user_id_;
}
void copy_to_primary_buffer(td::CSlice text);
void copy_to_clipboard(td::CSlice text);
void copy_to_buffer(td::CSlice text, bool primary) {
if (primary) {
copy_to_primary_buffer(text);
} else {
copy_to_clipboard(text);
}
}
void open_document(td::CSlice file_path);
void open_link(td::CSlice url);
void update_tdlib_version(std::string version) {
tdlib_version_ = version;
}
td::CSlice tdlib_version() {
return tdlib_version_;
}
void set_backend_type(std::string backend_type) {
backend_type_ = backend_type;
}
td::CSlice backend_type() const {
return backend_type_;
}
bool notifications_enabled() const {
return notifications_enabled_;
}
void set_notifications_enabled(bool value) {
notifications_enabled_ = value;
}
const auto &scope_notification_settings(NotificationScope scope) const {
return scope_notification_settings_[(td::int32)scope];
}
void update_notification_sounds(td::tl_object_ptr<td::td_api::notificationSounds> s) {
notification_sounds_.clear();
for (auto &e : s->notification_sounds_) {
auto id = e->id_;
notification_sounds_[id] = std::move(e);
}
}
const auto ¬ification_sounds() const {
return notification_sounds_;
}
const td::td_api::accentColor *get_accent_color(td::int32 color_id) const {
auto it = accent_colors_.find(color_id);
if (it == accent_colors_.end()) {
return nullptr;
} else {
return it->second.get();
}
}
windows::ColorRGB builtin_color(td::int32 id) {
CHECK(id >= 0 && id <= 6);
static const std::vector<windows::ColorRGB> colors{windows::ColorRGB{0xff0000}, windows::ColorRGB{0xff6600},
windows::ColorRGB{0x7f00ff}, windows::ColorRGB{0x00ff00},
windows::ColorRGB{0x00ffff}, windows::ColorRGB{0x0000ff},
windows::ColorRGB{0xf88379}};
return colors[id];
}
private:
std::array<td::tl_object_ptr<td::td_api::scopeNotificationSettings>, NotificationScopeCount>
scope_notification_settings_{};
std::vector<td::tl_object_ptr<td::td_api::chatFolderInfo>> chat_folders_;
td::int64 download_list_bytes_{0}, download_list_files_{0}, downloaded_bytes_{0};
std::vector<td::int32> saved_animations_;
td::tl_object_ptr<td::td_api::background> default_dark_background_;
td::tl_object_ptr<td::td_api::background> default_light_background_;
std::vector<td::tl_object_ptr<td::td_api::chatTheme>> chat_themes_;
std::map<td::int32, td::tl_object_ptr<td::td_api::accentColor>> accent_colors_;
std::vector<td::int32> available_accent_color_ids_;
std::vector<td::tl_object_ptr<td::td_api::profileAccentColor>> profile_accent_colors_;
std::vector<td::int32> profile_available_accent_color_ids_;
td::tl_object_ptr<td::td_api::ConnectionState> connection_state_ =
td::make_tl_object<td::td_api::connectionStateWaitingForNetwork>();
std::vector<td::tl_object_ptr<td::td_api::attachmentMenuBot>> attachment_menu_bots_;
std::vector<std::string> active_emoji_reactions_;
std::vector<td::int64> avaliable_message_reaction_effect_ids_;
std::vector<td::int64> avaliable_message_sticker_effect_ids_;
td::tl_object_ptr<td::td_api::ReactionType> default_reaction_type_;
td::tl_object_ptr<td::td_api::starAmount> stars_owned_;
std::vector<std::string> dice_emojis_;
std::string animation_search_provider_;
std::vector<std::string> animation_search_suggested_emojis_;
std::map<td::int64, td::tl_object_ptr<td::td_api::notificationSound>> notification_sounds_;
std::string copy_command_;
std::string link_open_command_;
std::string file_open_command_;
td::int64 my_user_id_{0};
bool notifications_enabled_{true};
std::string tdlib_version_;
std::string backend_type_;
};
extern GlobalParameters &global_parameters();
}; // namespace tdcurses