diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index a91ea87f0..535f6dbc8 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -3352,6 +3352,17 @@ storyInfo story_id:int32 date:int32 is_for_close_friends:Bool = StoryInfo; chatActiveStories chat_id:int53 list:StoryList order:int53 max_read_story_id:int32 stories:vector = ChatActiveStories; +//@description Describes current boost status of a chat +//@is_boosted True, if the current user has already boosted the chat +//@level Current boost level of the chat +//@boost_count The number of times the chat was boosted +//@current_level_boost_count The number of boosts added to reach the current level +//@next_level_boost_count The number of boosts needed to reach the next level; 0 if the next level isn't available +//@premium_member_count Approximate number of Telegram Premium subscribers joined the chat; always 0 if the current user isn't an administrator in the chat +//@premium_member_percentage A percentage of Telegram Premium subscribers joined the chat; always 0 if the current user isn't an administrator in the chat +chatBoostStatus is_boosted:Bool level:int32 boost_count:int32 current_level_boost_count:int32 next_level_boost_count:int32 premium_member_count:int32 premium_member_percentage:double = ChatBoostStatus; + + //@class CallDiscardReason @description Describes the reason why a call was discarded //@description The call wasn't discarded, or the reason is unknown @@ -7639,6 +7650,10 @@ reportStory story_sender_chat_id:int53 story_id:int32 reason:ReportReason text:s activateStoryStealthMode = Ok; +//@description Returns the current boost status for a channel chat @chat_id The identifier of the channel chat +getChatBoostStatus chat_id:int53 = ChatBoostStatus; + + //@description Returns information about a bot that can be added to attachment or side menu @bot_user_id Bot's user identifier getAttachmentMenuBot bot_user_id:int53 = AttachmentMenuBot; diff --git a/td/telegram/StoryManager.cpp b/td/telegram/StoryManager.cpp index 5b3c978b0..3f0881e56 100644 --- a/td/telegram/StoryManager.cpp +++ b/td/telegram/StoryManager.cpp @@ -739,6 +739,68 @@ class ActivateStealthModeQuery final : public Td::ResultHandler { } }; +class GetBoostsStatusQuery final : public Td::ResultHandler { + Promise> promise_; + DialogId dialog_id_; + + public: + explicit GetBoostsStatusQuery(Promise> &&promise) + : promise_(std::move(promise)) { + } + + void send(DialogId dialog_id) { + dialog_id_ = dialog_id; + auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read); + CHECK(input_peer != nullptr); + send_query( + G()->net_query_creator().create(telegram_api::stories_getBoostsStatus(std::move(input_peer)), {{dialog_id}})); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto result = result_ptr.move_as_ok(); + LOG(DEBUG) << "Receive result for GetBoostsStatusQuery: " << to_string(result); + if (result->level_ < 0 || result->current_level_boosts_ < 0 || result->boosts_ < result->current_level_boosts_ || + (result->next_level_boosts_ != 0 && result->boosts_ >= result->next_level_boosts_)) { + LOG(ERROR) << "Receive invalid " << to_string(result); + if (result->level_ < 0) { + result->level_ = 0; + } + if (result->current_level_boosts_ < 0) { + result->current_level_boosts_ = 0; + } + if (result->boosts_ < result->current_level_boosts_) { + result->boosts_ = result->current_level_boosts_; + } + if (result->next_level_boosts_ != 0 && result->boosts_ >= result->next_level_boosts_) { + result->next_level_boosts_ = result->boosts_ + 1; + } + } + int32 premium_member_count = 0; + double premium_member_percentage = 0.0; + if (result->premium_audience_ != nullptr) { + auto part = static_cast(result->premium_audience_->part_); + auto total = static_cast(result->premium_audience_->total_); + premium_member_count = max(0, part); + if (result->premium_audience_->total_ > 0) { + premium_member_percentage = 100.0 * premium_member_count / max(total, premium_member_count); + } + } + promise_.set_value(td_api::make_object( + result->my_boost_, result->level_, result->boosts_, result->current_level_boosts_, result->next_level_boosts_, + premium_member_count, premium_member_percentage)); + } + + void on_error(Status status) final { + td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetBoostsStatusQuery"); + promise_.set_error(std::move(status)); + } +}; + class CanSendStoryQuery final : public Td::ResultHandler { Promise> promise_; DialogId dialog_id_; @@ -2733,6 +2795,18 @@ void StoryManager::activate_stealth_mode(Promise &&promise) { td_->create_handler(std::move(promise))->send(); } +void StoryManager::get_dialog_boost_status(DialogId dialog_id, + Promise> &&promise) { + if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_dialog_boost_status")) { + return promise.set_error(Status::Error(400, "Chat not found")); + } + if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) { + return promise.set_error(Status::Error(400, "Can't access the chat")); + } + + td_->create_handler(std::move(promise))->send(dialog_id); +} + bool StoryManager::have_story(StoryFullId story_full_id) const { return get_story(story_full_id) != nullptr; } diff --git a/td/telegram/StoryManager.h b/td/telegram/StoryManager.h index ffeedb07f..f11c1d000 100644 --- a/td/telegram/StoryManager.h +++ b/td/telegram/StoryManager.h @@ -258,6 +258,8 @@ class StoryManager final : public Actor { void activate_stealth_mode(Promise &&promise); + void get_dialog_boost_status(DialogId dialog_id, Promise> &&promise); + void remove_story_notifications_by_story_ids(DialogId dialog_id, const vector &story_ids); StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr &&story_item_ptr); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 8e56a8027..b9dcd5a76 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6580,6 +6580,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::getChatBoostStatus &request) { + CHECK_IS_USER(); + CREATE_REQUEST_PROMISE(); + story_manager_->get_dialog_boost_status(DialogId(request.chat_id_), std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::getAttachmentMenuBot &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 5ccf5c80d..a4f8a6f1f 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1038,6 +1038,8 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::activateStoryStealthMode &request); + void on_request(uint64 id, const td_api::getChatBoostStatus &request); + void on_request(uint64 id, const td_api::getAttachmentMenuBot &request); void on_request(uint64 id, const td_api::toggleBotIsAddedToAttachmentMenu &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 5b604c28c..ec611c771 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4288,6 +4288,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 == "gcbs") { + ChatId chat_id; + get_args(args, chat_id); + send_request(td_api::make_object(chat_id)); } else if (op == "gamb") { UserId user_id; get_args(args, user_id);