diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d4eacdbe5..6c4bb19d4 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3636,6 +3636,21 @@ publicForwardStory story:story = PublicForward; publicForwards total_count:int32 forwards:vector next_offset:string = PublicForwards; +//@description Contains list of features available on a specific chat boost level +//@level Target chat boost level +//@story_per_day_count Number of stories that the chat can publish daily +//@custom_emoji_reaction_count Number of custom emoji reactions that can be added to the list of available reactions +//@title_color_count Number of custom colors for chat title +//@profile_accent_color_count Number of custom colors for profile photo background +//@can_set_profile_background_custom_emoji True, if custom emoji for profile background can be set +//@accent_color_count Number of custom colors for background of empty chat photo, replies to messages and link previews +//@can_set_background_custom_emoji True, if custom emoji for reply header and link preview background can be set +//@can_set_emoji_status True, if emoji status can be set +//@chat_theme_background_count Number of chat theme backgrounds that can be set as chat background +//@can_set_custom_background True, if custom background can be set in the chat for all users +chatBoostLevelFeatures level:int32 story_per_day_count:int32 custom_emoji_reaction_count:int32 title_color_count:int32 profile_accent_color_count:int32 can_set_profile_background_custom_emoji:Bool accent_color_count:int32 can_set_background_custom_emoji:Bool can_set_emoji_status:Bool chat_theme_background_count:int32 can_set_custom_background:Bool = ChatBoostLevelFeatures; + + //@class ChatBoostSource @description Describes source of a chat boost //@description The chat created a Telegram Premium gift code for a user @@ -8252,6 +8267,9 @@ activateStoryStealthMode = Ok; getStoryPublicForwards story_sender_chat_id:int53 story_id:int32 offset:string limit:int32 = PublicForwards; +//@description Returns list of features available on the specific chat boost level; this is an offline request @level Chat boost level +getChatBoostLevelFeatures level:int32 = ChatBoostLevelFeatures; + //@description Returns the list of available chat boost slots for the current user getAvailableChatBoostSlots = ChatBoostSlots; diff --git a/td/telegram/BoostManager.cpp b/td/telegram/BoostManager.cpp index 01d7e355e..4b3d3af48 100644 --- a/td/telegram/BoostManager.cpp +++ b/td/telegram/BoostManager.cpp @@ -13,8 +13,10 @@ #include "td/telegram/LinkManager.h" #include "td/telegram/MessageId.h" #include "td/telegram/MessagesManager.h" +#include "td/telegram/OptionManager.h" #include "td/telegram/ServerMessageId.h" #include "td/telegram/Td.h" +#include "td/telegram/ThemeManager.h" #include "td/telegram/UserId.h" #include "td/utils/algorithm.h" @@ -340,6 +342,25 @@ void BoostManager::tear_down() { parent_.reset(); } +td_api::object_ptr BoostManager::get_chat_boost_level_features_object( + 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 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 = + actual_level >= td_->option_manager_->get_option_integer("channel_bg_icon_level_min"); + auto can_set_emoji_status = + actual_level >= td_->option_manager_->get_option_integer("channel_emoji_status_level_min"); + auto can_set_custom_background = + actual_level >= td_->option_manager_->get_option_integer("channel_custom_wallpaper_level_min"); + return td_api::make_object( + level, actual_level, actual_level, theme_counts.title_color_count_, theme_counts.profile_accent_color_count_, + can_set_profile_background_custom_emoji, theme_counts.accent_color_count_, can_set_background_custom_emoji, + can_set_emoji_status, theme_counts.chat_theme_count_, can_set_custom_background); +} + void BoostManager::get_boost_slots(Promise> &&promise) { td_->create_handler(std::move(promise))->send(); } diff --git a/td/telegram/BoostManager.h b/td/telegram/BoostManager.h index 4bac1e0fd..8403d61be 100644 --- a/td/telegram/BoostManager.h +++ b/td/telegram/BoostManager.h @@ -29,6 +29,8 @@ class BoostManager final : public Actor { public: BoostManager(Td *td, ActorShared<> parent); + td_api::object_ptr get_chat_boost_level_features_object(int32 level) const; + void get_boost_slots(Promise> &&promise); void get_dialog_boost_status(DialogId dialog_id, Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 45ab3b0bb..8dd139346 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6715,6 +6715,12 @@ void Td::on_request(uint64 id, const td_api::activateStoryStealthMode &request) story_manager_->activate_stealth_mode(std::move(promise)); } +void Td::on_request(uint64 id, const td_api::getChatBoostLevelFeatures &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + promise.set_value(boost_manager_->get_chat_boost_level_features_object(request.level_)); +} + void Td::on_request(uint64 id, const td_api::getAvailableChatBoostSlots &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 6c2b361e1..511270994 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1069,6 +1069,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::activateStoryStealthMode &request); + void on_request(uint64 id, const td_api::getChatBoostLevelFeatures &request); + void on_request(uint64 id, const td_api::getAvailableChatBoostSlots &request); void on_request(uint64 id, const td_api::getChatBoostStatus &request); diff --git a/td/telegram/ThemeManager.cpp b/td/telegram/ThemeManager.cpp index d654191ad..55e179252 100644 --- a/td/telegram/ThemeManager.cpp +++ b/td/telegram/ThemeManager.cpp @@ -11,6 +11,7 @@ #include "td/telegram/Global.h" #include "td/telegram/logevent/LogEvent.h" #include "td/telegram/net/NetQueryCreator.h" +#include "td/telegram/OptionManager.h" #include "td/telegram/Td.h" #include "td/telegram/TdDb.h" #include "td/telegram/telegram_api.h" @@ -432,6 +433,35 @@ void ThemeManager::tear_down() { parent_.reset(); } +ThemeManager::DialogBoostAvailableCounts ThemeManager::get_dialog_boost_available_count(int32 level) { + 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]) { + result.accent_color_count_++; + + if (accent_colors_.accent_color_ids_[i].is_built_in()) { + result.title_color_count_++; + continue; + } + + auto it = accent_colors_.light_colors_.find(accent_colors_.accent_color_ids_[i]); + CHECK(it != accent_colors_.light_colors_.end()); + if (it->second.size() == 1) { + result.title_color_count_++; + } + } + } + for (size_t i = 0; i < profile_accent_colors_.min_boost_levels_.size(); i++) { + if (level >= profile_accent_colors_.min_boost_levels_[i]) { + result.profile_accent_color_count_++; + } + } + return result; +} + bool ThemeManager::is_dark_base_theme(BaseTheme base_theme) { switch (base_theme) { case BaseTheme::Classic: diff --git a/td/telegram/ThemeManager.h b/td/telegram/ThemeManager.h index dababceb3..655176fd8 100644 --- a/td/telegram/ThemeManager.h +++ b/td/telegram/ThemeManager.h @@ -44,6 +44,14 @@ class ThemeManager final : public Actor { 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); + void get_current_state(vector> &updates) const; private: diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index ee01cec4d..a82a77890 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4446,6 +4446,10 @@ class CliClient final : public Actor { send_request(td_api::make_object(story_sender_chat_id, story_id, reason, text)); } else if (op == "assm") { send_request(td_api::make_object()); + } else if (op == "gcblf") { + int32 level; + get_args(args, level); + send_request(td_api::make_object(level)); } else if (op == "gacbs") { send_request(td_api::make_object()); } else if (op == "gcbs") {