Add td_api::getChatBoostLevelFeatures.

This commit is contained in:
levlam 2023-12-26 20:20:41 +03:00
parent 0edbb14ad2
commit 54bd830f49
8 changed files with 91 additions and 0 deletions

View File

@ -3636,6 +3636,21 @@ publicForwardStory story:story = PublicForward;
publicForwards total_count:int32 forwards:vector<PublicForward> 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;

View File

@ -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<td_api::chatBoostLevelFeatures> BoostManager::get_chat_boost_level_features_object(
int32 level) const {
int32 actual_level =
clamp(level, 0, static_cast<int32>(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<td_api::chatBoostLevelFeatures>(
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<td_api::object_ptr<td_api::chatBoostSlots>> &&promise) {
td_->create_handler<GetMyBoostsQuery>(std::move(promise))->send();
}

View File

@ -29,6 +29,8 @@ class BoostManager final : public Actor {
public:
BoostManager(Td *td, ActorShared<> parent);
td_api::object_ptr<td_api::chatBoostLevelFeatures> get_chat_boost_level_features_object(int32 level) const;
void get_boost_slots(Promise<td_api::object_ptr<td_api::chatBoostSlots>> &&promise);
void get_dialog_boost_status(DialogId dialog_id, Promise<td_api::object_ptr<td_api::chatBoostStatus>> &&promise);

View File

@ -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();

View File

@ -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);

View File

@ -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<int32>(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:

View File

@ -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<td_api::object_ptr<td_api::Update>> &updates) const;
private:

View File

@ -4446,6 +4446,10 @@ class CliClient final : public Actor {
send_request(td_api::make_object<td_api::reportStory>(story_sender_chat_id, story_id, reason, text));
} else if (op == "assm") {
send_request(td_api::make_object<td_api::activateStoryStealthMode>());
} else if (op == "gcblf") {
int32 level;
get_args(args, level);
send_request(td_api::make_object<td_api::getChatBoostLevelFeatures>(level));
} else if (op == "gacbs") {
send_request(td_api::make_object<td_api::getAvailableChatBoostSlots>());
} else if (op == "gcbs") {