diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index eb0ccab89..c3d3bb1e8 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -761,8 +761,9 @@ profileAccentColors palette_colors:vector background_colors:vector //@id Profile accent color identifier //@light_theme_colors Accent colors expected to be used in light themes //@dark_theme_colors Accent colors expected to be used in dark themes -//@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; +//@min_supergroup_chat_boost_level The minimum chat boost level required to use the color in a supergroup chat +//@min_channel_chat_boost_level The minimum chat boost level required to use the color in a channel chat +profileAccentColor id:int32 light_theme_colors:profileAccentColors dark_theme_colors:profileAccentColors min_supergroup_chat_boost_level:int32 min_channel_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 diff --git a/td/telegram/BoostManager.cpp b/td/telegram/BoostManager.cpp index 836aead9b..d7dc05f7a 100644 --- a/td/telegram/BoostManager.cpp +++ b/td/telegram/BoostManager.cpp @@ -348,7 +348,7 @@ td_api::object_ptr BoostManager::get_chat_boost_ int32 level) const { int32 actual_level = clamp(level, 0, static_cast(td_->option_manager_->get_option_integer("chat_boost_level_max"))); - auto theme_counts = td_->theme_manager_->get_dialog_boost_available_count(actual_level); + auto theme_counts = td_->theme_manager_->get_dialog_boost_available_count(actual_level, false); auto can_set_profile_background_custom_emoji = actual_level >= td_->option_manager_->get_option_integer("channel_profile_bg_icon_level_min"); auto can_set_background_custom_emoji = diff --git a/td/telegram/ThemeManager.cpp b/td/telegram/ThemeManager.cpp index b7d767f3f..a9fd91c92 100644 --- a/td/telegram/ThemeManager.cpp +++ b/td/telegram/ThemeManager.cpp @@ -213,10 +213,12 @@ void ThemeManager::ChatThemes::parse(ParserT &parser) { template void ThemeManager::AccentColors::store(StorerT &storer) const { bool has_hash = hash_ != 0; - bool has_min_boost_levels = !min_boost_levels_.empty(); + bool has_min_broadcast_boost_levels = !min_broadcast_boost_levels_.empty(); + bool has_min_megagroup_boost_levels = !min_megagroup_boost_levels_.empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(has_hash); - STORE_FLAG(has_min_boost_levels); + STORE_FLAG(has_min_broadcast_boost_levels); + STORE_FLAG(has_min_megagroup_boost_levels); END_STORE_FLAGS(); td::store(static_cast(light_colors_.size()), storer); for (auto &it : light_colors_) { @@ -232,18 +234,23 @@ 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); + if (has_min_broadcast_boost_levels) { + td::store(min_broadcast_boost_levels_, storer); + } + if (has_min_megagroup_boost_levels) { + td::store(min_megagroup_boost_levels_, storer); } } template void ThemeManager::AccentColors::parse(ParserT &parser) { bool has_hash; - bool has_min_boost_levels; + bool has_min_broadcast_boost_levels; + bool has_min_megagroup_boost_levels; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_hash); - PARSE_FLAG(has_min_boost_levels); + PARSE_FLAG(has_min_broadcast_boost_levels); + PARSE_FLAG(has_min_megagroup_boost_levels); END_PARSE_FLAGS(); int32 size; td::parse(size, parser); @@ -268,11 +275,14 @@ void ThemeManager::AccentColors::parse(ParserT &parser) { if (has_hash) { td::parse(hash_, parser); } - if (has_min_boost_levels) { - td::parse(min_boost_levels_, parser); + if (has_min_broadcast_boost_levels) { + td::parse(min_broadcast_boost_levels_, parser); } else { hash_ = 0; } + if (has_min_megagroup_boost_levels) { + td::parse(min_megagroup_boost_levels_, parser); + } } template @@ -292,10 +302,12 @@ void ThemeManager::ProfileAccentColor::parse(ParserT &parser) { template void ThemeManager::ProfileAccentColors::store(StorerT &storer) const { bool has_hash = hash_ != 0; - bool has_min_boost_levels = !min_boost_levels_.empty(); + bool has_min_broadcast_boost_levels = !min_broadcast_boost_levels_.empty(); + bool has_min_megagroup_boost_levels = !min_megagroup_boost_levels_.empty(); BEGIN_STORE_FLAGS(); STORE_FLAG(has_hash); - STORE_FLAG(has_min_boost_levels); + STORE_FLAG(has_min_broadcast_boost_levels); + STORE_FLAG(has_min_megagroup_boost_levels); END_STORE_FLAGS(); td::store(static_cast(light_colors_.size()), storer); for (auto &it : light_colors_) { @@ -311,18 +323,23 @@ 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); + if (has_min_broadcast_boost_levels) { + td::store(min_broadcast_boost_levels_, storer); + } + if (has_min_megagroup_boost_levels) { + td::store(min_megagroup_boost_levels_, storer); } } template void ThemeManager::ProfileAccentColors::parse(ParserT &parser) { bool has_hash; - bool has_min_boost_levels; + bool has_min_broadcast_boost_levels; + bool has_min_megagroup_boost_levels; BEGIN_PARSE_FLAGS(); PARSE_FLAG(has_hash); - PARSE_FLAG(has_min_boost_levels); + PARSE_FLAG(has_min_broadcast_boost_levels); + PARSE_FLAG(has_min_megagroup_boost_levels); END_PARSE_FLAGS(); int32 size; td::parse(size, parser); @@ -347,8 +364,13 @@ void ThemeManager::ProfileAccentColors::parse(ParserT &parser) { if (has_hash) { td::parse(hash_, parser); } - if (has_min_boost_levels) { - td::parse(min_boost_levels_, parser); + if (has_min_broadcast_boost_levels) { + td::parse(min_broadcast_boost_levels_, parser); + } else { + hash_ = 0; + } + if (has_min_megagroup_boost_levels) { + td::parse(min_megagroup_boost_levels_, parser); } else { hash_ = 0; } @@ -433,13 +455,16 @@ void ThemeManager::tear_down() { parent_.reset(); } -ThemeManager::DialogBoostAvailableCounts ThemeManager::get_dialog_boost_available_count(int32 level) { +ThemeManager::DialogBoostAvailableCounts ThemeManager::get_dialog_boost_available_count(int32 level, + bool for_megagroup) { DialogBoostAvailableCounts result; if (level >= td_->option_manager_->get_option_integer("channel_wallpaper_level_min")) { result.chat_theme_count_ = static_cast(chat_themes_.themes.size()); } - for (size_t i = 0; i < accent_colors_.min_boost_levels_.size(); i++) { - if (level >= accent_colors_.min_boost_levels_[i]) { + auto &min_boost_levels = + for_megagroup ? accent_colors_.min_megagroup_boost_levels_ : accent_colors_.min_broadcast_boost_levels_; + for (size_t i = 0; i < min_boost_levels.size(); i++) { + if (level >= min_boost_levels[i]) { result.accent_color_count_++; if (accent_colors_.accent_color_ids_[i].is_built_in()) { @@ -454,8 +479,10 @@ ThemeManager::DialogBoostAvailableCounts ThemeManager::get_dialog_boost_availabl } } } - for (size_t i = 0; i < profile_accent_colors_.min_boost_levels_.size(); i++) { - if (level >= profile_accent_colors_.min_boost_levels_[i]) { + auto &min_profile_boost_levels = for_megagroup ? profile_accent_colors_.min_megagroup_boost_levels_ + : profile_accent_colors_.min_broadcast_boost_levels_; + for (size_t i = 0; i < min_profile_boost_levels.size(); i++) { + if (level >= min_profile_boost_levels[i]) { result.profile_accent_color_count_++; } } @@ -518,7 +545,9 @@ void ThemeManager::on_update_theme(telegram_api::object_ptr bool ThemeManager::on_update_accent_colors(FlatHashMap, AccentColorIdHash> light_colors, FlatHashMap, AccentColorIdHash> dark_colors, - vector accent_color_ids, vector min_boost_levels) { + vector accent_color_ids, + vector min_broadcast_boost_levels, + vector min_megagroup_boost_levels) { auto are_equal = [](const FlatHashMap, AccentColorIdHash> &lhs, const FlatHashMap, AccentColorIdHash> &rhs) { for (auto &lhs_it : lhs) { @@ -529,7 +558,9 @@ bool ThemeManager::on_update_accent_colors(FlatHashMap light_colors, FlatHashMap dark_colors, - vector accent_color_ids, vector min_boost_levels) { + vector accent_color_ids, vector min_broadcast_boost_levels, + vector min_megagroup_boost_levels) { auto are_equal = [](const FlatHashMap &lhs, const FlatHashMap &rhs) { for (auto &lhs_it : lhs) { @@ -562,7 +595,8 @@ 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_ && + min_broadcast_boost_levels == profile_accent_colors_.min_broadcast_boost_levels_ && + min_megagroup_boost_levels == profile_accent_colors_.min_megagroup_boost_levels_ && are_equal(light_colors, profile_accent_colors_.light_colors_) && are_equal(dark_colors, profile_accent_colors_.dark_colors_)) { return false; @@ -574,7 +608,8 @@ 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); + profile_accent_colors_.min_broadcast_boost_levels_ = std::move(min_broadcast_boost_levels); + profile_accent_colors_.min_megagroup_boost_levels_ = std::move(min_megagroup_boost_levels); save_profile_accent_colors(); send_update_profile_accent_colors(); @@ -702,10 +737,10 @@ td_api::object_ptr 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 min_boost_levels; - for (size_t i = 0; i < min_boost_levels_.size(); i++) { + FlatHashMap min_broadcast_boost_levels; + for (size_t i = 0; i < min_broadcast_boost_levels_.size(); i++) { CHECK(i < accent_color_ids_.size()); - min_boost_levels[accent_color_ids_[i]] = min_boost_levels_[i]; + min_broadcast_boost_levels[accent_color_ids_[i]] = min_broadcast_boost_levels_[i]; } for (auto &it : light_colors_) { auto light_colors = it.second; @@ -724,7 +759,8 @@ td_api::object_ptr ThemeManager::AccentColors::get_u } } colors.push_back(td_api::make_object(it.first.get(), best_index, std::move(light_colors), - std::move(dark_colors), min_boost_levels[it.first])); + std::move(dark_colors), + min_broadcast_boost_levels[it.first])); } auto available_accent_color_ids = transform(accent_color_ids_, [](AccentColorId accent_color_id) { return accent_color_id.get(); }); @@ -748,10 +784,15 @@ td_api::object_ptr ThemeManager::ProfileAccentColor td_api::object_ptr ThemeManager::ProfileAccentColors::get_update_profile_accent_colors_object() const { - FlatHashMap min_boost_levels; - for (size_t i = 0; i < min_boost_levels_.size(); i++) { + FlatHashMap min_broadcast_boost_levels; + for (size_t i = 0; i < min_broadcast_boost_levels_.size(); i++) { CHECK(i < accent_color_ids_.size()); - min_boost_levels[accent_color_ids_[i]] = min_boost_levels_[i]; + min_broadcast_boost_levels[accent_color_ids_[i]] = min_broadcast_boost_levels_[i]; + } + FlatHashMap min_megagroup_boost_levels; + for (size_t i = 0; i < min_megagroup_boost_levels_.size(); i++) { + CHECK(i < accent_color_ids_.size()); + min_megagroup_boost_levels[accent_color_ids_[i]] = min_megagroup_boost_levels_[i]; } vector> colors; for (auto &it : light_colors_) { @@ -760,7 +801,8 @@ ThemeManager::ProfileAccentColors::get_update_profile_accent_colors_object() con 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( - it.first.get(), std::move(light_colors), std::move(dark_colors), min_boost_levels[it.first])); + it.first.get(), std::move(light_colors), std::move(dark_colors), min_megagroup_boost_levels[it.first], + min_broadcast_boost_levels[it.first])); } auto available_accent_color_ids = transform(accent_color_ids_, [](AccentColorId accent_color_id) { return accent_color_id.get(); }); @@ -895,7 +937,8 @@ void ThemeManager::on_get_accent_colors(Result, AccentColorIdHash> light_colors; FlatHashMap, AccentColorIdHash> dark_colors; vector accent_color_ids; - vector min_boost_levels; + vector min_broadcast_boost_levels; + vector min_megagroup_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)) { @@ -932,7 +975,8 @@ void ThemeManager::on_get_accent_colors(Resulthidden_) { accent_color_ids.push_back(accent_color_id); - min_boost_levels.push_back(max(0, option->channel_min_level_)); + min_broadcast_boost_levels.push_back(max(0, option->channel_min_level_)); + min_megagroup_boost_levels.push_back(max(0, option->group_min_level_)); } if (!current_light_colors.empty()) { light_colors[accent_color_id] = std::move(current_light_colors); @@ -948,7 +992,7 @@ void ThemeManager::on_get_accent_colors(Result light_colors; FlatHashMap dark_colors; vector accent_color_ids; - vector min_boost_levels; + vector min_broadcast_boost_levels; + vector min_megagroup_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 || @@ -1009,7 +1054,8 @@ 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_)); + min_broadcast_boost_levels.push_back(max(0, option->channel_min_level_)); + min_megagroup_boost_levels.push_back(max(0, option->group_min_level_)); } light_colors[accent_color_id] = std::move(current_light_color); dark_colors[accent_color_id] = std::move(current_dark_color); @@ -1021,7 +1067,7 @@ void ThemeManager::on_get_profile_accent_colors( is_changed = true; } if (!on_update_profile_accent_colors(std::move(light_colors), std::move(dark_colors), std::move(accent_color_ids), - std::move(min_boost_levels)) && + std::move(min_broadcast_boost_levels), std::move(min_megagroup_boost_levels)) && is_changed) { save_profile_accent_colors(); } diff --git a/td/telegram/ThemeManager.h b/td/telegram/ThemeManager.h index d305f4b3d..f6af72723 100644 --- a/td/telegram/ThemeManager.h +++ b/td/telegram/ThemeManager.h @@ -50,7 +50,7 @@ class ThemeManager final : public Actor { int32 profile_accent_color_count_ = 0; int32 chat_theme_count_ = 0; }; - DialogBoostAvailableCounts get_dialog_boost_available_count(int32 level); + DialogBoostAvailableCounts get_dialog_boost_available_count(int32 level, bool for_megagroup); void get_current_state(vector> &updates) const; @@ -105,7 +105,8 @@ class ThemeManager final : public Actor { FlatHashMap, AccentColorIdHash> light_colors_; FlatHashMap, AccentColorIdHash> dark_colors_; vector accent_color_ids_; - vector min_boost_levels_; + vector min_broadcast_boost_levels_; + vector min_megagroup_boost_levels_; int32 hash_ = 0; td_api::object_ptr get_update_accent_colors_object() const; @@ -141,7 +142,8 @@ class ThemeManager final : public Actor { FlatHashMap light_colors_; FlatHashMap dark_colors_; vector accent_color_ids_; - vector min_boost_levels_; + vector min_broadcast_boost_levels_; + vector min_megagroup_boost_levels_; int32 hash_ = 0; td_api::object_ptr get_update_profile_accent_colors_object() const; @@ -169,13 +171,15 @@ class ThemeManager final : public Actor { bool on_update_accent_colors(FlatHashMap, AccentColorIdHash> light_colors, FlatHashMap, AccentColorIdHash> dark_colors, - vector accent_color_ids, vector min_boost_levels); + vector accent_color_ids, vector min_broadcast_boost_levels, + vector min_megagroup_boost_levels); void on_get_accent_colors(Result> result); bool on_update_profile_accent_colors(FlatHashMap light_colors, FlatHashMap dark_colors, - vector accent_color_ids, vector min_boost_levels); + vector accent_color_ids, vector min_broadcast_boost_levels, + vector min_megagroup_boost_levels); ProfileAccentColor get_profile_accent_color( telegram_api::object_ptr &&color_set) const;