Add td_api::updateAccentColors.

This commit is contained in:
levlam 2023-11-02 21:30:38 +03:00
parent 08888d5ead
commit 4489ef54aa
3 changed files with 50 additions and 4 deletions

View File

@ -743,8 +743,13 @@ premiumGiveawayInfoOngoing creation_date:int32 status:PremiumGiveawayParticipant
premiumGiveawayInfoCompleted creation_date:int32 actual_winners_selection_date:int32 was_refunded:Bool winner_count:int32 activation_count:int32 gift_code:string = PremiumGiveawayInfo;
//@description Contains accent color identifier for user/chat name, and backgrounds of chat photo, replies and link previews
//@id Accent color identifier; 0 - red, 1 - orange, 2 - purple/violet, 3 - green, 4 - cyan, 5 - blue, 6 - pink
//@description Contains information about supported accent color for user/chat name, background of empty chat photo, replies to messages and link previews
//@id Accent color identifier
//@light_theme_colors The list of 1-3 colors in RGB format, describing the accent color, as expected to be shown in light themes
//@dark_theme_colors The list of 1-3 colors in RGB format, describing the accent color, as expected to be shown in dark themes
accentColor id:int32 light_theme_colors:vector<int32> dark_theme_colors:vector<int32> = AccentColor;
//@description Contains accent color identifier for user/chat name, and backgrounds of chat photo, replies and link previews @id Accent color identifier
accentColorId id:int32 = AccentColorId;
//@description Describes a custom emoji to be shown instead of the Telegram Premium badge
@ -6329,6 +6334,12 @@ updateSelectedBackground for_dark_theme:Bool background:background = Update;
//@description The list of available chat themes has changed @chat_themes The new list of chat themes
updateChatThemes chat_themes:vector<chatTheme> = Update;
//@description The list of supported accent colors has changed
//@colors Information about supported colors; colors with identifiers 0 (red), 1 (orange), 2 (purple/violet), 3 (green), 4 (cyan), 5 (blue), 6 (pink) must be always supported
//-and aren't included in the list. The exact colors for the accent colors with identifiers 0-6 must be taken from the app theme
//@available_accent_color_ids The list of accent color identifiers, which can be set through setAccentColor and setChatAccentColor. The colors must be shown in the specififed order
updateAccentColors colors:vector<accentColor> available_accent_color_ids:vector<int32> = Update;
//@description Some language pack strings have been updated @localization_target Localization target to which the language pack belongs @language_pack_id Identifier of the updated language pack @strings List of changed language pack strings; empty if all strings have changed
updateLanguagePackStrings localization_target:string language_pack_id:string strings:vector<languagePackString> = Update;

View File

@ -263,6 +263,8 @@ void ThemeManager::on_update_accent_colors(FlatHashMap<AccentColorId, vector<int
accent_colors_.dark_colors_[it.first] = std::move(it.second);
}
accent_colors_.accent_color_ids_ = std::move(accent_color_ids);
send_update_accent_colors();
}
namespace {
@ -347,6 +349,24 @@ td_api::object_ptr<td_api::updateChatThemes> ThemeManager::get_update_chat_theme
transform(chat_themes_.themes, [this](const ChatTheme &theme) { return get_chat_theme_object(theme); }));
}
td_api::object_ptr<td_api::updateAccentColors> ThemeManager::get_update_accent_colors_object() const {
return accent_colors_.get_update_accent_colors_object();
}
td_api::object_ptr<td_api::updateAccentColors> ThemeManager::AccentColors::get_update_accent_colors_object() const {
vector<td_api::object_ptr<td_api::accentColor>> colors;
for (auto &it : light_colors_) {
auto light_colors = it.second;
auto dark_it = dark_colors_.find(it.first);
auto dark_colors = dark_it != dark_colors_.end() ? dark_it->second : light_colors;
colors.push_back(
td_api::make_object<td_api::accentColor>(it.first.get(), std::move(light_colors), std::move(dark_colors)));
}
auto available_accent_color_ids =
transform(accent_color_ids_, [](AccentColorId accent_color_id) { return accent_color_id.get(); });
return td_api::make_object<td_api::updateAccentColors>(std::move(colors), std::move(available_accent_color_ids));
}
string ThemeManager::get_chat_themes_database_key() {
return "chat_themes";
}
@ -359,6 +379,10 @@ void ThemeManager::send_update_chat_themes() const {
send_closure(G()->td(), &Td::send_update, get_update_chat_themes_object());
}
void ThemeManager::send_update_accent_colors() const {
send_closure(G()->td(), &Td::send_update, get_update_accent_colors_object());
}
void ThemeManager::on_get_chat_themes(Result<telegram_api::object_ptr<telegram_api::account_Themes>> result) {
if (result.is_error()) {
set_timeout_in(Random::fast(40, 60));
@ -455,11 +479,16 @@ ThemeManager::ThemeSettings ThemeManager::get_chat_theme_settings(
}
void ThemeManager::get_current_state(vector<td_api::object_ptr<td_api::Update>> &updates) const {
if (!td_->auth_manager_->is_authorized() || td_->auth_manager_->is_bot() || chat_themes_.themes.empty()) {
if (!td_->auth_manager_->is_authorized() || td_->auth_manager_->is_bot()) {
return;
}
updates.push_back(get_update_chat_themes_object());
if (!chat_themes_.themes.empty()) {
updates.push_back(get_update_chat_themes_object());
}
if (!accent_colors_.accent_color_ids_.empty()) {
updates.push_back(get_update_accent_colors_object());
}
}
} // namespace td

View File

@ -93,6 +93,8 @@ class ThemeManager final : public Actor {
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors_;
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors_;
vector<AccentColorId> accent_color_ids_;
td_api::object_ptr<td_api::updateAccentColors> get_update_accent_colors_object() const;
};
void start_up() final;
@ -121,6 +123,10 @@ class ThemeManager final : public Actor {
ThemeSettings get_chat_theme_settings(telegram_api::object_ptr<telegram_api::themeSettings> settings);
td_api::object_ptr<td_api::updateAccentColors> get_update_accent_colors_object() const;
void send_update_accent_colors() const;
ChatThemes chat_themes_;
AccentColors accent_colors_;