Add min_chat_boost_level to accentColor/profileAccentColor.

This commit is contained in:
levlam 2023-12-21 18:48:15 +03:00
parent 022c227515
commit 88b2781685
3 changed files with 60 additions and 13 deletions

View File

@ -748,7 +748,8 @@ premiumGiveawayInfoCompleted creation_date:int32 actual_winners_selection_date:i
//@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 built_in_accent_color_id:int32 light_theme_colors:vector<int32> dark_theme_colors:vector<int32> = AccentColor;
//@min_chat_boost_level The minimum chat boost level required to use the color
accentColor id:int32 built_in_accent_color_id:int32 light_theme_colors:vector<int32> dark_theme_colors:vector<int32> min_chat_boost_level:int32 = AccentColor;
//@description Contains information about supported accent colors for user profile photo background in RGB format
//@palette_colors The list of 1-2 colors in RGB format, describing the colors, as expected to be shown in the color palette settings
@ -760,7 +761,8 @@ profileAccentColors palette_colors:vector<int32> background_colors:vector<int32>
//@id Profile accent color identifier
//@light_theme_colors Description of accent colors expected to be used in light themes
//@dark_theme_colors Description of accent colors expected to be used in dark themes
profileAccentColor id:int32 light_theme_colors:profileAccentColors dark_theme_colors:profileAccentColors = ProfileAccentColor;
//@min_chat_boost_level The minimum chat boost level required to use the color
profileAccentColor id:int32 light_theme_colors:profileAccentColors dark_theme_colors:profileAccentColors min_chat_boost_level:int32 = ProfileAccentColor;
//@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

@ -212,8 +212,10 @@ void ThemeManager::ChatThemes::parse(ParserT &parser) {
template <class StorerT>
void ThemeManager::AccentColors::store(StorerT &storer) const {
bool has_hash = hash_ != 0;
bool has_min_boost_levels = !min_boost_levels_.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_hash);
STORE_FLAG(has_min_boost_levels);
END_STORE_FLAGS();
td::store(static_cast<int32>(light_colors_.size()), storer);
for (auto &it : light_colors_) {
@ -229,13 +231,18 @@ void ThemeManager::AccentColors::store(StorerT &storer) const {
if (has_hash) {
td::store(hash_, storer);
}
if (has_min_boost_levels) {
td::store(min_boost_levels_, storer);
}
}
template <class ParserT>
void ThemeManager::AccentColors::parse(ParserT &parser) {
bool has_hash;
bool has_min_boost_levels;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_hash);
PARSE_FLAG(has_min_boost_levels);
END_PARSE_FLAGS();
int32 size;
td::parse(size, parser);
@ -260,6 +267,11 @@ void ThemeManager::AccentColors::parse(ParserT &parser) {
if (has_hash) {
td::parse(hash_, parser);
}
if (has_min_boost_levels) {
td::parse(min_boost_levels_, parser);
} else {
hash_ = 0;
}
}
template <class StorerT>
@ -279,8 +291,10 @@ void ThemeManager::ProfileAccentColor::parse(ParserT &parser) {
template <class StorerT>
void ThemeManager::ProfileAccentColors::store(StorerT &storer) const {
bool has_hash = hash_ != 0;
bool has_min_boost_levels = !min_boost_levels_.empty();
BEGIN_STORE_FLAGS();
STORE_FLAG(has_hash);
STORE_FLAG(has_min_boost_levels);
END_STORE_FLAGS();
td::store(static_cast<int32>(light_colors_.size()), storer);
for (auto &it : light_colors_) {
@ -296,13 +310,18 @@ void ThemeManager::ProfileAccentColors::store(StorerT &storer) const {
if (has_hash) {
td::store(hash_, storer);
}
if (has_min_boost_levels) {
td::store(min_boost_levels_, storer);
}
}
template <class ParserT>
void ThemeManager::ProfileAccentColors::parse(ParserT &parser) {
bool has_hash;
bool has_min_boost_levels;
BEGIN_PARSE_FLAGS();
PARSE_FLAG(has_hash);
PARSE_FLAG(has_min_boost_levels);
END_PARSE_FLAGS();
int32 size;
td::parse(size, parser);
@ -327,6 +346,11 @@ void ThemeManager::ProfileAccentColors::parse(ParserT &parser) {
if (has_hash) {
td::parse(hash_, parser);
}
if (has_min_boost_levels) {
td::parse(min_boost_levels_, parser);
} else {
hash_ = 0;
}
}
ThemeManager::ThemeManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
@ -464,7 +488,7 @@ void ThemeManager::on_update_theme(telegram_api::object_ptr<telegram_api::theme>
bool ThemeManager::on_update_accent_colors(FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors,
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors,
vector<AccentColorId> accent_color_ids) {
vector<AccentColorId> accent_color_ids, vector<int32> min_boost_levels) {
auto are_equal = [](const FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> &lhs,
const FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> &rhs) {
for (auto &lhs_it : lhs) {
@ -475,8 +499,8 @@ bool ThemeManager::on_update_accent_colors(FlatHashMap<AccentColorId, vector<int
}
return true;
};
if (accent_color_ids == accent_colors_.accent_color_ids_ && are_equal(light_colors, accent_colors_.light_colors_) &&
are_equal(dark_colors, accent_colors_.dark_colors_)) {
if (accent_color_ids == accent_colors_.accent_color_ids_ && min_boost_levels == accent_colors_.min_boost_levels_ &&
are_equal(light_colors, accent_colors_.light_colors_) && are_equal(dark_colors, accent_colors_.dark_colors_)) {
return false;
}
for (auto &it : light_colors) {
@ -486,6 +510,7 @@ bool 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);
accent_colors_.min_boost_levels_ = std::move(min_boost_levels);
save_accent_colors();
send_update_accent_colors();
@ -495,7 +520,7 @@ bool ThemeManager::on_update_accent_colors(FlatHashMap<AccentColorId, vector<int
bool ThemeManager::on_update_profile_accent_colors(
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> light_colors,
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> dark_colors,
vector<AccentColorId> accent_color_ids) {
vector<AccentColorId> accent_color_ids, vector<int32> min_boost_levels) {
auto are_equal = [](const FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> &lhs,
const FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> &rhs) {
for (auto &lhs_it : lhs) {
@ -507,6 +532,7 @@ bool ThemeManager::on_update_profile_accent_colors(
return true;
};
if (accent_color_ids == profile_accent_colors_.accent_color_ids_ &&
min_boost_levels == profile_accent_colors_.min_boost_levels_ &&
are_equal(light_colors, profile_accent_colors_.light_colors_) &&
are_equal(dark_colors, profile_accent_colors_.dark_colors_)) {
return false;
@ -518,6 +544,7 @@ bool ThemeManager::on_update_profile_accent_colors(
profile_accent_colors_.dark_colors_[it.first] = std::move(it.second);
}
profile_accent_colors_.accent_color_ids_ = std::move(accent_color_ids);
profile_accent_colors_.min_boost_levels_ = std::move(min_boost_levels);
save_profile_accent_colors();
send_update_profile_accent_colors();
@ -645,6 +672,11 @@ td_api::object_ptr<td_api::updateAccentColors> ThemeManager::AccentColors::get_u
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);
};
FlatHashMap<AccentColorId, int32, AccentColorIdHash> min_boost_levels;
for (size_t i = 0; i < min_boost_levels_.size(); i++) {
CHECK(i < accent_color_ids_.size());
min_boost_levels[accent_color_ids_[i]] = min_boost_levels_[i];
}
for (auto &it : light_colors_) {
auto light_colors = it.second;
auto dark_it = dark_colors_.find(it.first);
@ -662,7 +694,7 @@ td_api::object_ptr<td_api::updateAccentColors> ThemeManager::AccentColors::get_u
}
}
colors.push_back(td_api::make_object<td_api::accentColor>(it.first.get(), best_index, std::move(light_colors),
std::move(dark_colors)));
std::move(dark_colors), min_boost_levels[it.first]));
}
auto available_accent_color_ids =
transform(accent_color_ids_, [](AccentColorId accent_color_id) { return accent_color_id.get(); });
@ -686,14 +718,19 @@ td_api::object_ptr<td_api::profileAccentColors> ThemeManager::ProfileAccentColor
td_api::object_ptr<td_api::updateProfileAccentColors>
ThemeManager::ProfileAccentColors::get_update_profile_accent_colors_object() const {
FlatHashMap<AccentColorId, int32, AccentColorIdHash> min_boost_levels;
for (size_t i = 0; i < min_boost_levels_.size(); i++) {
CHECK(i < accent_color_ids_.size());
min_boost_levels[accent_color_ids_[i]] = min_boost_levels_[i];
}
vector<td_api::object_ptr<td_api::profileAccentColor>> colors;
for (auto &it : light_colors_) {
auto light_colors = it.second.get_profile_accent_colors_object();
auto dark_it = dark_colors_.find(it.first);
auto dark_colors = dark_it != dark_colors_.end() ? dark_it->second.get_profile_accent_colors_object()
: it.second.get_profile_accent_colors_object();
colors.push_back(td_api::make_object<td_api::profileAccentColor>(it.first.get(), std::move(light_colors),
std::move(dark_colors)));
colors.push_back(td_api::make_object<td_api::profileAccentColor>(
it.first.get(), std::move(light_colors), std::move(dark_colors), min_boost_levels[it.first]));
}
auto available_accent_color_ids =
transform(accent_color_ids_, [](AccentColorId accent_color_id) { return accent_color_id.get(); });
@ -828,6 +865,7 @@ void ThemeManager::on_get_accent_colors(Result<telegram_api::object_ptr<telegram
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors;
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors;
vector<AccentColorId> accent_color_ids;
vector<int32> min_boost_levels;
for (auto &option : peer_colors->colors_) {
if ((option->colors_ != nullptr && option->colors_->get_id() != telegram_api::help_peerColorSet::ID) ||
(option->dark_colors_ != nullptr && option->dark_colors_->get_id() != telegram_api::help_peerColorSet::ID)) {
@ -864,6 +902,7 @@ void ThemeManager::on_get_accent_colors(Result<telegram_api::object_ptr<telegram
}
if (!option->hidden_) {
accent_color_ids.push_back(accent_color_id);
min_boost_levels.push_back(max(0, option->channel_min_level_));
}
if (!current_light_colors.empty()) {
light_colors[accent_color_id] = std::move(current_light_colors);
@ -878,7 +917,8 @@ void ThemeManager::on_get_accent_colors(Result<telegram_api::object_ptr<telegram
accent_colors_.hash_ = peer_colors->hash_;
is_changed = true;
}
if (!on_update_accent_colors(std::move(light_colors), std::move(dark_colors), std::move(accent_color_ids)) &&
if (!on_update_accent_colors(std::move(light_colors), std::move(dark_colors), std::move(accent_color_ids),
std::move(min_boost_levels)) &&
is_changed) {
save_accent_colors();
}
@ -921,6 +961,7 @@ void ThemeManager::on_get_profile_accent_colors(
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> light_colors;
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> dark_colors;
vector<AccentColorId> accent_color_ids;
vector<int32> min_boost_levels;
for (auto &option : peer_colors->colors_) {
AccentColorId accent_color_id(option->color_id_);
if (option->colors_ == nullptr || option->colors_->get_id() != telegram_api::help_peerColorProfileSet::ID ||
@ -938,6 +979,7 @@ void ThemeManager::on_get_profile_accent_colors(
}
if (!option->hidden_) {
accent_color_ids.push_back(accent_color_id);
min_boost_levels.push_back(max(0, option->channel_min_level_));
}
light_colors[accent_color_id] = std::move(current_light_color);
dark_colors[accent_color_id] = std::move(current_dark_color);
@ -948,7 +990,8 @@ void ThemeManager::on_get_profile_accent_colors(
profile_accent_colors_.hash_ = peer_colors->hash_;
is_changed = true;
}
if (!on_update_profile_accent_colors(std::move(light_colors), std::move(dark_colors), std::move(accent_color_ids)) &&
if (!on_update_profile_accent_colors(std::move(light_colors), std::move(dark_colors), std::move(accent_color_ids),
std::move(min_boost_levels)) &&
is_changed) {
save_profile_accent_colors();
}

View File

@ -97,6 +97,7 @@ class ThemeManager final : public Actor {
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> light_colors_;
FlatHashMap<AccentColorId, vector<int32>, AccentColorIdHash> dark_colors_;
vector<AccentColorId> accent_color_ids_;
vector<int32> min_boost_levels_;
int32 hash_ = 0;
td_api::object_ptr<td_api::updateAccentColors> get_update_accent_colors_object() const;
@ -132,6 +133,7 @@ class ThemeManager final : public Actor {
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> light_colors_;
FlatHashMap<AccentColorId, ProfileAccentColor, AccentColorIdHash> dark_colors_;
vector<AccentColorId> accent_color_ids_;
vector<int32> min_boost_levels_;
int32 hash_ = 0;
td_api::object_ptr<td_api::updateProfileAccentColors> get_update_profile_accent_colors_object() const;
@ -159,13 +161,13 @@ class ThemeManager final : public Actor {
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<AccentColorId> accent_color_ids, vector<int32> min_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<AccentColorId> accent_color_ids, vector<int32> min_boost_levels);
ProfileAccentColor get_profile_accent_color(
telegram_api::object_ptr<telegram_api::help_PeerColorSet> &&color_set) const;