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
|
//
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2026
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#pragma once
#include "td/telegram/AccentColorId.h"
#include "td/telegram/td_api.h"
#include "td/telegram/telegram_api.h"
#include "td/telegram/ThemeSettings.h"
#include "td/actor/actor.h"
#include "td/utils/common.h"
#include "td/utils/FlatHashMap.h"
#include "td/utils/Promise.h"
#include "td/utils/Status.h"
namespace td {
class Td;
class ThemeManager final : public Actor {
public:
ThemeManager(Td *td, ActorShared<> parent);
void init();
void on_update_theme(telegram_api::object_ptr<telegram_api::theme> &&theme, Promise<Unit> &&promise);
void reload_chat_themes();
void reload_accent_colors();
void reload_profile_accent_colors();
static string get_theme_parameters_json_string(const td_api::object_ptr<td_api::themeParameters> &theme);
int32 get_accent_color_id_object(AccentColorId accent_color_id,
AccentColorId fallback_accent_color_id = AccentColorId()) const;
int32 get_profile_accent_color_id_object(AccentColorId accent_color_id) const;
struct DialogBoostAvailableCounts {
int32 title_color_count_ = 0;
int32 accent_color_count_ = 0;
int32 profile_accent_color_count_ = 0;
int32 chat_theme_count_ = 0;
};
DialogBoostAvailableCounts get_dialog_boost_available_count(int32 level, bool for_megagroup);
void get_unique_gift_chat_themes(const string &offset, int32 limit,
Promise<td_api::object_ptr<td_api::giftChatThemes>> &&promise);
void get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const;
private:
struct EmojiChatTheme {
string emoji;
int64 id = 0;
ThemeSettings light_theme;
ThemeSettings dark_theme;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
struct EmojiChatThemes {
int64 hash = 0;
vector<EmojiChatTheme> themes;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
struct AccentColors {
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors_;
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors_;
vector<AccentColorId> accent_color_ids_;
vector<int32> min_broadcast_boost_levels_;
vector<int32> min_megagroup_boost_levels_;
int32 hash_ = 0;
td_api::object_ptr<td_api::updateAccentColors> get_update_accent_colors_object() const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
struct ProfileAccentColor {
vector<int32> palette_colors_;
vector<int32> background_colors_;
vector<int32> story_colors_;
bool is_valid() const;
td_api::object_ptr<td_api::profileAccentColors> get_profile_accent_colors_object() const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
friend bool operator==(const ProfileAccentColor &lhs, const ProfileAccentColor &rhs);
friend bool operator!=(const ProfileAccentColor &lhs, const ProfileAccentColor &rhs);
struct ProfileAccentColors {
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> light_colors_;
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> dark_colors_;
vector<AccentColorId> accent_color_ids_;
vector<int32> min_broadcast_boost_levels_;
vector<int32> min_megagroup_boost_levels_;
int32 hash_ = 0;
td_api::object_ptr<td_api::updateProfileAccentColors> get_update_profile_accent_colors_object() const;
template <class StorerT>
void store(StorerT &storer) const;
template <class ParserT>
void parse(ParserT &parser);
};
void start_up() final;
void tear_down() final;
void load_chat_themes();
void load_accent_colors();
void load_profile_accent_colors();
void on_get_chat_themes(Result<telegram_api::object_ptr<telegram_api::account_Themes>> result);
bool on_update_accent_colors(FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors,
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors,
vector<AccentColorId> accent_color_ids, vector<int32> min_broadcast_boost_levels,
vector<int32> min_megagroup_boost_levels);
void on_get_accent_colors(Result<telegram_api::object_ptr<telegram_api::help_PeerColors>> result);
bool on_update_profile_accent_colors(FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> light_colors,
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> dark_colors,
vector<AccentColorId> accent_color_ids, vector<int32> min_broadcast_boost_levels,
vector<int32> min_megagroup_boost_levels);
ProfileAccentColor get_profile_accent_color(
telegram_api::object_ptr<telegram_api::help_PeerColorSet> &&color_set) const;
void on_get_profile_accent_colors(Result<telegram_api::object_ptr<telegram_api::help_PeerColors>> result);
td_api::object_ptr<td_api::emojiChatTheme> get_emoji_chat_theme_object(const EmojiChatTheme &theme) const;
td_api::object_ptr<td_api::updateEmojiChatThemes> get_update_emoji_chat_themes_object() const;
static string get_chat_themes_database_key();
string get_accent_colors_database_key();
string get_profile_accent_colors_database_key();
void save_chat_themes();
void save_accent_colors();
void save_profile_accent_colors();
void send_update_chat_themes() const;
td_api::object_ptr<td_api::updateAccentColors> get_update_accent_colors_object() const;
td_api::object_ptr<td_api::updateProfileAccentColors> get_update_profile_accent_colors_object() const;
void send_update_accent_colors() const;
void send_update_profile_accent_colors() const;
EmojiChatThemes chat_themes_;
AccentColors accent_colors_;
ProfileAccentColors profile_accent_colors_;
Td *td_;
ActorShared<> parent_;
};
} // namespace td
|