From 81f959be99155aea17640fae9809b6541312216d Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 11 Feb 2024 01:29:07 +0300 Subject: [PATCH] Support supergroups in getChatBoostFeatures, --- td/generate/scheme/td_api.tl | 39 +++++++++++++++++++----------- td/telegram/BoostManager.cpp | 47 +++++++++++++++++++++--------------- td/telegram/BoostManager.h | 5 ++-- td/telegram/Td.cpp | 8 +++--- td/telegram/cli.cpp | 9 ++++--- 5 files changed, 65 insertions(+), 43 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index c04883d63..0b861aef4 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3735,16 +3735,20 @@ publicForwards total_count:int32 forwards:vector next_offset:stri //@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; +//@can_set_custom_emoji_sticker_set True, if custom emoji sticker set can be set for the chat +//@can_recognize_speech True, if speech recognition can be used for video note and voice note messages by 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 can_set_custom_emoji_sticker_set:Bool can_recognize_speech:Bool = ChatBoostLevelFeatures; //@description Contains a list of features available on the first chat boost levels //@features The list of features //@min_profile_background_custom_emoji_boost_level The minimum boost level required to set custom emoji for profile background -//@min_background_custom_emoji_boost_level The minimum boost level required to set custom emoji for reply header and link preview background +//@min_background_custom_emoji_boost_level The minimum boost level required to set custom emoji for reply header and link preview background; for channel chats only //@min_emoji_status_boost_level The minimum boost level required to set emoji status //@min_chat_theme_background_boost_level The minimum boost level required to set a chat theme background as chat background //@min_custom_background_boost_level The minimum boost level required to set custom chat background -chatBoostFeatures features:vector min_profile_background_custom_emoji_boost_level:int32 min_background_custom_emoji_boost_level:int32 min_emoji_status_boost_level:int32 min_chat_theme_background_boost_level:int32 min_custom_background_boost_level:int32 = ChatBoostFeatures; +//@min_custom_emoji_sticker_set_boost_level The minimum boost level required to set custom emoji sticker set for the chat; for supergroup chats only +//@min_speech_recognition_boost_level The minimum boost level allowing to recognize speech in video note and voice note messages for non-Premium chat members; for supergroup chats only +chatBoostFeatures features:vector min_profile_background_custom_emoji_boost_level:int32 min_background_custom_emoji_boost_level:int32 min_emoji_status_boost_level:int32 min_chat_theme_background_boost_level:int32 min_custom_background_boost_level:int32 min_custom_emoji_sticker_set_boost_level:int32 min_speech_recognition_boost_level:int32 = ChatBoostFeatures; //@class ChatBoostSource @description Describes source of a chat boost @@ -4793,7 +4797,7 @@ premiumFeatureSavedMessagesTags = PremiumFeature; //@class PremiumStoryFeature @description Describes a story feature available to Premium users -//@description Stories of the current user are displayed before stories of non-premium contacts and channels +//@description Stories of the current user are displayed before stories of non-Premium contacts and channels premiumStoryFeaturePriorityOrder = PremiumStoryFeature; //@description The ability to hide the fact that the user viewed other's stories @@ -8528,35 +8532,40 @@ 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 list of features available on the specific chat boost level; this is an offline request +//@is_channel Pass true to get the list of features for channels; pass false to get the list of features for supergroups +//@level Chat boost level +getChatBoostLevelFeatures is_channel:Bool level:int32 = ChatBoostLevelFeatures; //@description Returns list of features available on the first 10 chat boost levels; this is an offline request -getChatBoostFeatures = ChatBoostFeatures; +//@is_channel Pass true to get the list of features for channels; pass false to get the list of features for supergroups +getChatBoostFeatures is_channel:Bool = ChatBoostFeatures; //@description Returns the list of available chat boost slots for the current user getAvailableChatBoostSlots = ChatBoostSlots; -//@description Returns the current boost status for a channel chat @chat_id Identifier of the channel chat +//@description Returns the current boost status for a supergroup or a channel chat @chat_id Identifier of the chat getChatBoostStatus chat_id:int53 = ChatBoostStatus; -//@description Boosts a chat and returns the list of available chat boost slots for the current user after the boost @chat_id Identifier of the chat @slot_ids Identifiers of boost slots of the current user from which to apply boosts to the chat +//@description Boosts a chat and returns the list of available chat boost slots for the current user after the boost +//@chat_id Identifier of the chat +//@slot_ids Identifiers of boost slots of the current user from which to apply boosts to the chat boostChat chat_id:int53 slot_ids:vector = ChatBoostSlots; -//@description Returns an HTTPS link to boost the specified channel chat @chat_id Identifier of the chat +//@description Returns an HTTPS link to boost the specified supergroup or channel chat @chat_id Identifier of the chat getChatBoostLink chat_id:int53 = ChatBoostLink; //@description Returns information about a link to boost a chat. Can be called for any internal link of the type internalLinkTypeChatBoost @url The link to boost a chat getChatBoostLinkInfo url:string = ChatBoostLinkInfo; -//@description Returns list of boosts applied to a chat; requires administrator rights in the channel chat +//@description Returns list of boosts applied to a chat; requires administrator rights in the chat //@chat_id Identifier of the chat //@only_gift_codes Pass true to receive only boosts received from gift codes and giveaways created by the chat //@offset Offset of the first entry to return as received from the previous request; use empty string to get the first chunk of results //@limit The maximum number of boosts to be returned; up to 100. For optimal performance, the number of returned boosts can be smaller than the specified limit getChatBoosts chat_id:int53 only_gift_codes:Bool offset:string limit:int32 = FoundChatBoosts; -//@description Returns list of boosts applied to a chat by a given user; requires administrator rights in the channel chat; for bots only +//@description Returns list of boosts applied to a chat by a given user; requires administrator rights in the chat; for bots only //@chat_id Identifier of the chat //@user_id Identifier of the user getUserChatBoosts chat_id:int53 user_id:int53 = FoundChatBoosts; @@ -9370,13 +9379,15 @@ toggleSupergroupUsernameIsActive supergroup_id:int53 username:string is_active:B //@description Disables all active non-editable usernames of a supergroup or channel, requires owner privileges in the supergroup or channel @supergroup_id Identifier of the supergroup or channel disableAllSupergroupUsernames supergroup_id:int53 = Ok; -//@description Changes order of active usernames of a supergroup or channel, requires owner privileges in the supergroup or channel @supergroup_id Identifier of the supergroup or channel @usernames The new order of active usernames. All currently active usernames must be specified +//@description Changes order of active usernames of a supergroup or channel, requires owner privileges in the supergroup or channel +//@supergroup_id Identifier of the supergroup or channel +//@usernames The new order of active usernames. All currently active usernames must be specified reorderSupergroupActiveUsernames supergroup_id:int53 usernames:vector = Ok; //@description Changes the sticker set of a supergroup; requires can_change_info administrator right @supergroup_id Identifier of the supergroup @sticker_set_id New value of the supergroup sticker set identifier. Use 0 to remove the supergroup sticker set setSupergroupStickerSet supergroup_id:int53 sticker_set_id:int64 = Ok; -//@description Changes the sticker set of a supergroup; requires can_change_info administrator right. The chat must have at least chatBoostFeatures.min_custom_emoji_sticker_set_boost_level boost level to pass the corresponding color +//@description Changes the custom emoji sticker set of a supergroup; requires can_change_info administrator right. The chat must have at least chatBoostFeatures.min_custom_emoji_sticker_set_boost_level boost level to pass the corresponding color //@supergroup_id Identifier of the supergroup //@custom_emoji_sticker_set_id New value of the custom emoji sticker set identifier for the supergroup. Use 0 to remove the custom emoji sticker set in the supergroup setSupergroupCustomEmojiStickerSet supergroup_id:int53 custom_emoji_sticker_set_id:int64 = Ok; diff --git a/td/telegram/BoostManager.cpp b/td/telegram/BoostManager.cpp index 3d6084640..1b03a75c8 100644 --- a/td/telegram/BoostManager.cpp +++ b/td/telegram/BoostManager.cpp @@ -345,35 +345,42 @@ void BoostManager::tear_down() { } td_api::object_ptr BoostManager::get_chat_boost_level_features_object( - int32 level) const { + bool for_megagroup, 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, 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 = - 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"); + auto have_enough_boost_level = [&](Slice name) { + auto needed_boost_level = narrow_cast(td_->option_manager_->get_option_integer( + PSLICE() << (for_megagroup ? "group" : "channel") << '_' << name << "_level_min")); + return needed_boost_level != 0 && actual_level >= needed_boost_level; + }; + auto theme_counts = td_->theme_manager_->get_dialog_boost_available_count(actual_level, for_megagroup); + auto can_set_profile_background_custom_emoji = have_enough_boost_level("profile_bg_icon"); + auto can_set_background_custom_emoji = have_enough_boost_level("bg_icon"); + auto can_set_emoji_status = have_enough_boost_level("emoji_status"); + auto can_set_custom_background = have_enough_boost_level("custom_wallpaper"); + auto can_set_custom_emoji_sticker_set = have_enough_boost_level("emoji_stickers"); + auto can_recognize_speech = have_enough_boost_level("transcribe"); 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); + level, actual_level, for_megagroup ? 0 : 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, can_set_custom_emoji_sticker_set, + can_recognize_speech); } -td_api::object_ptr BoostManager::get_chat_boost_features_object() const { +td_api::object_ptr BoostManager::get_chat_boost_features_object(bool for_megagroup) const { vector> features; for (int32 level = 1; level <= 10; level++) { - features.push_back(get_chat_boost_level_features_object(level)); + features.push_back(get_chat_boost_level_features_object(for_megagroup, level)); } auto get_min_boost_level = [&](Slice name) { - return narrow_cast(td_->option_manager_->get_option_integer(PSLICE() << "channel_" << name << "_level_min")); + return narrow_cast(td_->option_manager_->get_option_integer( + PSLICE() << (for_megagroup ? "group" : "channel") << '_' << name << "_level_min", 1000000000)); }; return td_api::make_object( - std::move(features), get_min_boost_level("profile_bg_icon"), get_min_boost_level("profile_bg_icon"), - get_min_boost_level("emoji_status"), get_min_boost_level("wallpaper"), get_min_boost_level("custom_wallpaper")); + std::move(features), get_min_boost_level("profile_bg_icon"), get_min_boost_level("bg_icon"), + get_min_boost_level("emoji_status"), get_min_boost_level("wallpaper"), get_min_boost_level("custom_wallpaper"), + get_min_boost_level("emoji_stickers"), get_min_boost_level("transcribe")); } void BoostManager::get_boost_slots(Promise> &&promise) { @@ -394,7 +401,7 @@ void BoostManager::get_dialog_boost_status(DialogId dialog_id, void BoostManager::boost_dialog(DialogId dialog_id, vector slot_ids, Promise> &&promise) { - if (!td_->dialog_manager_->have_dialog_force(dialog_id, "get_dialog_boost_status")) { + if (!td_->dialog_manager_->have_dialog_force(dialog_id, "boost_dialog")) { return promise.set_error(Status::Error(400, "Chat not found")); } if (!td_->dialog_manager_->have_input_peer(dialog_id, AccessRights::Read)) { @@ -408,7 +415,7 @@ void BoostManager::boost_dialog(DialogId dialog_id, vector slot_ids, } Result> BoostManager::get_dialog_boost_link(DialogId dialog_id) { - if (!td_->dialog_manager_->have_dialog_force(dialog_id, "get_dialog_boost_status")) { + if (!td_->dialog_manager_->have_dialog_force(dialog_id, "get_dialog_boost_link")) { return Status::Error(400, "Chat not found"); } if (!td_->dialog_manager_->have_input_peer(dialog_id, AccessRights::Read)) { diff --git a/td/telegram/BoostManager.h b/td/telegram/BoostManager.h index efcb26325..99854892e 100644 --- a/td/telegram/BoostManager.h +++ b/td/telegram/BoostManager.h @@ -29,9 +29,10 @@ class BoostManager final : public Actor { public: BoostManager(Td *td, ActorShared<> parent); - td_api::object_ptr get_chat_boost_level_features_object(int32 level) const; + td_api::object_ptr get_chat_boost_level_features_object(bool for_megagroup, + int32 level) const; - td_api::object_ptr get_chat_boost_features_object() const; + td_api::object_ptr get_chat_boost_features_object(bool for_megagroup) const; void get_boost_slots(Promise> &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 336ef6cdb..e676e7eb5 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6771,13 +6771,13 @@ void Td::on_request(uint64 id, const td_api::activateStoryStealthMode &request) 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_)); + promise.set_value(boost_manager_->get_chat_boost_level_features_object(!request.is_channel_, request.level_)); } void Td::on_request(uint64 id, const td_api::getChatBoostFeatures &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); - promise.set_value(boost_manager_->get_chat_boost_features_object()); + promise.set_value(boost_manager_->get_chat_boost_features_object(!request.is_channel_)); } void Td::on_request(uint64 id, const td_api::getAvailableChatBoostSlots &request) { @@ -7798,8 +7798,8 @@ void Td::on_request(uint64 id, const td_api::setSupergroupStickerSet &request) { void Td::on_request(uint64 id, const td_api::setSupergroupCustomEmojiStickerSet &request) { CREATE_OK_REQUEST_PROMISE(); - contacts_manager_->set_channel_emoji_sticker_set(ChannelId(request.supergroup_id_), - StickerSetId(request.custom_emoji_sticker_set_id_), std::move(promise)); + contacts_manager_->set_channel_emoji_sticker_set( + ChannelId(request.supergroup_id_), StickerSetId(request.custom_emoji_sticker_set_id_), std::move(promise)); } void Td::on_request(uint64 id, const td_api::toggleSupergroupSignMessages &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index f4e48bf71..841c0105f 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4534,11 +4534,14 @@ class CliClient final : public Actor { } else if (op == "assm") { send_request(td_api::make_object()); } else if (op == "gcblf") { + bool is_channel; int32 level; - get_args(args, level); - send_request(td_api::make_object(level)); + get_args(args, is_channel, level); + send_request(td_api::make_object(is_channel, level)); } else if (op == "gcbf") { - send_request(td_api::make_object()); + bool is_channel; + get_args(args, is_channel); + send_request(td_api::make_object(is_channel)); } else if (op == "gacbs") { send_request(td_api::make_object()); } else if (op == "gcbs") {