Add accentColor.built_in_accent_color_id.

This commit is contained in:
levlam 2023-11-02 23:37:42 +03:00
parent adc81fcea6
commit 2a9c7555be
3 changed files with 24 additions and 4 deletions

View File

@ -745,9 +745,10 @@ premiumGiveawayInfoCompleted creation_date:int32 actual_winners_selection_date:i
//@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
//@built_in_accent_color_id Identifier of a built-in color to use in places, where only one color is needed; 0-6
//@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;
accentColor id:int32 built_in_accent_color_id:int32 light_theme_colors:vector<int32> dark_theme_colors:vector<int32> = AccentColor;
//@description Describes a custom emoji to be shown instead of the Telegram Premium badge
//@custom_emoji_id Identifier of the custom emoji in stickerFormatTgs format

View File

@ -1984,7 +1984,7 @@ void ConfigManager::process_app_config(tl_object_ptr<telegram_api::JSONValue> &c
colors.push_back(static_cast<int32>(r_color.ok()));
}
}
if (colors.size() != colors_json.size()) {
if (colors.empty() || colors.size() != colors_json.size()) {
LOG(ERROR) << "Receive invalid colors for " << accent_color_id;
color_map.erase(accent_color_id);
}

View File

@ -424,12 +424,31 @@ td_api::object_ptr<td_api::updateAccentColors> ThemeManager::get_update_accent_c
td_api::object_ptr<td_api::updateAccentColors> ThemeManager::AccentColors::get_update_accent_colors_object() const {
vector<td_api::object_ptr<td_api::accentColor>> colors;
int32 base_colors[] = {0xDF2020, 0xDFA520, 0xA040A0, 0x208020, 0x20DFDF, 0x2044DF, 0xDF1493};
auto get_distance = [](int32 lhs_color, int32 rhs_color) {
auto get_color_distance = [](int32 lhs, int32 rhs) {
auto diff = max(lhs & 255, 0) - max(rhs & 255, 0);
return diff * diff;
};
return get_color_distance(lhs_color, rhs_color) + get_color_distance(lhs_color >> 8, rhs_color >> 8) +
get_color_distance(lhs_color >> 16, rhs_color >> 16);
};
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 first_color = light_colors[0];
int best_index = 0;
int32 best_distance = get_distance(base_colors[0], first_color);
for (int i = 1; i < 7; i++) {
auto cur_distance = get_distance(base_colors[i], first_color);
if (cur_distance < best_distance) {
best_distance = cur_distance;
best_index = i;
}
}
colors.push_back(td_api::make_object<td_api::accentColor>(it.first.get(), best_index, 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(); });