Add td_api::boostChat.

This commit is contained in:
levlam 2023-09-15 15:11:37 +03:00
parent 97db1de2c1
commit 8230efb97f
6 changed files with 58 additions and 0 deletions

View File

@ -7683,6 +7683,9 @@ 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 Boosts a chat @chat_id Identifier of the chat
boostChat chat_id:int53 = Ok;
//@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

@ -842,6 +842,36 @@ class CanApplyBoostQuery final : public Td::ResultHandler {
}
};
class ApplyBoostQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
DialogId dialog_id_;
public:
explicit ApplyBoostQuery(Promise<Unit> &&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_applyBoost(std::move(input_peer)), {{dialog_id}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::stories_applyBoost>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
promise_.set_value(Unit());
}
void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "ApplyBoostQuery");
promise_.set_error(std::move(status));
}
};
class GetChatsToSendStoriesQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
@ -2946,6 +2976,17 @@ td_api::object_ptr<td_api::CanBoostChatResult> StoryManager::get_can_boost_chat_
return nullptr;
}
void StoryManager::boost_dialog(DialogId dialog_id, Promise<Unit> &&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<ApplyBoostQuery>(std::move(promise))->send(dialog_id);
}
bool StoryManager::have_story(StoryFullId story_full_id) const {
return get_story(story_full_id) != nullptr;
}

View File

@ -274,6 +274,8 @@ class StoryManager final : public Actor {
td_api::object_ptr<td_api::CanBoostChatResult> get_can_boost_chat_result_object(const Status &error) const;
void boost_dialog(DialogId dialog_id, Promise<Unit> &&promise);
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

@ -6598,6 +6598,12 @@ void Td::on_request(uint64 id, const td_api::canBoostChat &request) {
story_manager_->can_boost_dialog(DialogId(request.chat_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::boostChat &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
story_manager_->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

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

View File

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