Add td_api::canBoostChat.

This commit is contained in:
levlam 2023-09-15 15:00:02 +03:00
parent e2462e2487
commit 97db1de2c1
6 changed files with 137 additions and 2 deletions

View File

@ -4450,7 +4450,7 @@ chatTheme name:string light_settings:themeSettings dark_settings:themeSettings =
hashtags hashtags:vector<string> = Hashtags;
//@class CanSendStoryResult @description Represents result of checking whether the current user can send a story
//@class CanSendStoryResult @description Represents result of checking whether the current user can send a story in the specific chat
//@description A story can be sent
canSendStoryResultOk = CanSendStoryResult;
@ -4471,6 +4471,27 @@ canSendStoryResultWeeklyLimitExceeded retry_after:int32 = CanSendStoryResult;
canSendStoryResultMonthlyLimitExceeded retry_after:int32 = CanSendStoryResult;
//@class CanBoostChatResult @description Represents result of checking whether the current user can boost the specific chat
//@description The chat can be boosted @currently_boosted_chat_id Identifier of the currently boosted chat, from which boost will be removed; 0 if none
canBoostChatResultOk currently_boosted_chat_id:int53 = CanBoostChatResult;
//@description The chat can't be boosted
canBoostChatResultInvalidChat = CanBoostChatResult;
//@description The chat is already boosted by the user
canBoostChatResultAlreadyBoosted = CanBoostChatResult;
//@description The user must subscribe to Telegram Premium to be able to boost chats
canBoostChatResultPremiumNeeded = CanBoostChatResult;
//@description The user must have Telegram Premium subscription instead of a gifted Telegram Premium
canBoostChatResultPremiumSubscriptionNeeded = CanBoostChatResult;
//@description The user must wait the specified time before the boost can be moved to another chat @retry_after Time left before the user can boost another chat
canBoostChatResultWaitNeeded retry_after:int32 = CanBoostChatResult;
//@class CanTransferOwnershipResult @description Represents result of checking whether the current session can be used to transfer a chat ownership to another user
//@description The session can be used
@ -7656,9 +7677,12 @@ 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
//@description Returns the current boost status for a channel chat @chat_id Identifier of the channel chat
getChatBoostStatus chat_id:int53 = ChatBoostStatus;
//@description Checks whether the current user can boost a chat @chat_id Identifier of the chat
canBoostChat chat_id:int53 = CanBoostChatResult;
//@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;

View File

@ -804,6 +804,44 @@ class GetBoostsStatusQuery final : public Td::ResultHandler {
}
};
class CanApplyBoostQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::CanBoostChatResult>> promise_;
public:
explicit CanApplyBoostQuery(Promise<td_api::object_ptr<td_api::CanBoostChatResult>> &&promise)
: promise_(std::move(promise)) {
}
void send(DialogId dialog_id) {
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Read);
CHECK(input_peer != nullptr);
auto query =
G()->net_query_creator().create(telegram_api::stories_canApplyBoost(std::move(input_peer)), {{dialog_id}});
query->total_timeout_limit_ = 4;
send_query(std::move(query));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::stories_canApplyBoost>(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 CanApplyBoostQuery: " << to_string(result);
promise_.set_value(td_->story_manager_->get_can_boost_chat_result_object(std::move(result)));
}
void on_error(Status status) final {
auto result = td_->story_manager_->get_can_boost_chat_result_object(status);
if (result != nullptr) {
promise_.set_value(std::move(result));
} else {
promise_.set_error(std::move(status));
}
}
};
class GetChatsToSendStoriesQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
@ -2854,6 +2892,60 @@ void StoryManager::get_dialog_boost_status(DialogId dialog_id,
td_->create_handler<GetBoostsStatusQuery>(std::move(promise))->send(dialog_id);
}
void StoryManager::can_boost_dialog(DialogId dialog_id,
Promise<td_api::object_ptr<td_api::CanBoostChatResult>> &&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<CanApplyBoostQuery>(std::move(promise))->send(dialog_id);
}
td_api::object_ptr<td_api::CanBoostChatResult> StoryManager::get_can_boost_chat_result_object(
telegram_api::object_ptr<telegram_api::stories_CanApplyBoostResult> &&result) const {
CHECK(result != nullptr);
switch (result->get_id()) {
case telegram_api::stories_canApplyBoostOk::ID:
return td_api::make_object<td_api::canBoostChatResultOk>(0);
case telegram_api::stories_canApplyBoostReplace::ID: {
auto replace = telegram_api::move_object_as<telegram_api::stories_canApplyBoostReplace>(result);
td_->contacts_manager_->on_get_chats(std::move(replace->chats_), "get_can_boost_chat_result_object");
DialogId currently_boosted_dialog_id(replace->current_boost_);
td_->messages_manager_->force_create_dialog(currently_boosted_dialog_id, "get_can_boost_chat_result_object");
return td_api::make_object<td_api::canBoostChatResultOk>(
td_->messages_manager_->get_chat_id_object(currently_boosted_dialog_id, "get_can_boost_chat_result_object"));
}
default:
UNREACHABLE();
return nullptr;
}
}
td_api::object_ptr<td_api::CanBoostChatResult> StoryManager::get_can_boost_chat_result_object(
const Status &error) const {
CHECK(error.is_error());
if (error.message() == "PREMIUM_ACCOUNT_REQUIRED") {
return td_api::make_object<td_api::canBoostChatResultPremiumNeeded>();
}
if (error.message() == "PREMIUM_GIFTED_NOT_ALLOWED") {
return td_api::make_object<td_api::canBoostChatResultPremiumSubscriptionNeeded>();
}
if (error.message() == "BOOST_NOT_MODIFIED") {
return td_api::make_object<td_api::canBoostChatResultAlreadyBoosted>();
}
if (error.message() == "PEER_ID_INVALID") {
return td_api::make_object<td_api::canBoostChatResultInvalidChat>();
}
auto retry_after = Global::get_retry_after(error.code(), error.message());
if (retry_after > 0) {
return td_api::make_object<td_api::canBoostChatResultWaitNeeded>(retry_after);
}
return nullptr;
}
bool StoryManager::have_story(StoryFullId story_full_id) const {
return get_story(story_full_id) != nullptr;
}

View File

@ -267,6 +267,13 @@ class StoryManager final : public Actor {
void get_dialog_boost_status(DialogId dialog_id, Promise<td_api::object_ptr<td_api::chatBoostStatus>> &&promise);
void can_boost_dialog(DialogId dialog_id, Promise<td_api::object_ptr<td_api::CanBoostChatResult>> &&promise);
td_api::object_ptr<td_api::CanBoostChatResult> get_can_boost_chat_result_object(
telegram_api::object_ptr<telegram_api::stories_CanApplyBoostResult> &&result) const;
td_api::object_ptr<td_api::CanBoostChatResult> get_can_boost_chat_result_object(const Status &error) const;
void remove_story_notifications_by_story_ids(DialogId dialog_id, const vector<StoryId> &story_ids);
StoryId on_get_story(DialogId owner_dialog_id, telegram_api::object_ptr<telegram_api::StoryItem> &&story_item_ptr);

View File

@ -6592,6 +6592,12 @@ void Td::on_request(uint64 id, const td_api::getChatBoostStatus &request) {
story_manager_->get_dialog_boost_status(DialogId(request.chat_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::canBoostChat &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();
story_manager_->can_boost_dialog(DialogId(request.chat_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getAttachmentMenuBot &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();

View File

@ -1042,6 +1042,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getChatBoostStatus &request);
void on_request(uint64 id, const td_api::canBoostChat &request);
void on_request(uint64 id, const td_api::getAttachmentMenuBot &request);
void on_request(uint64 id, const td_api::toggleBotIsAddedToAttachmentMenu &request);

View File

@ -4294,6 +4294,10 @@ class CliClient final : public Actor {
ChatId chat_id;
get_args(args, chat_id);
send_request(td_api::make_object<td_api::getChatBoostStatus>(chat_id));
} else if (op == "cbc") {
ChatId chat_id;
get_args(args, chat_id);
send_request(td_api::make_object<td_api::canBoostChat>(chat_id));
} else if (op == "gamb") {
UserId user_id;
get_args(args, user_id);