Add td_api::getUserChatBoosts.

This commit is contained in:
levlam 2023-10-31 01:52:26 +03:00
parent 9e289e2046
commit d6f284e8cd
6 changed files with 86 additions and 2 deletions

View File

@ -7968,13 +7968,18 @@ 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. The user must be an administrator in the channel chat to get the list of boosts
//@description Returns list of boosts applied to a chat; requires administrator rights in the channel 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
//@chat_id Identifier of the chat
//@user_id Identifier of the user
getUserChatBoosts chat_id:int53 user_id:int53 = FoundChatBoosts;
//@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

@ -286,6 +286,54 @@ class GetBoostsListQuery final : public Td::ResultHandler {
}
};
class GetUserBoostsQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::foundChatBoosts>> promise_;
DialogId dialog_id_;
public:
explicit GetUserBoostsQuery(Promise<td_api::object_ptr<td_api::foundChatBoosts>> &&promise)
: promise_(std::move(promise)) {
}
void send(DialogId dialog_id, UserId user_id) {
dialog_id_ = dialog_id;
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id_, AccessRights::Read);
CHECK(input_peer != nullptr);
auto r_input_user = td_->contacts_manager_->get_input_user(user_id);
CHECK(r_input_user.is_ok());
send_query(G()->net_query_creator().create(
telegram_api::premium_getUserBoosts(std::move(input_peer), r_input_user.move_as_ok())));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::premium_getUserBoosts>(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 GetUserBoostsQuery: " << to_string(result);
td_->contacts_manager_->on_get_users(std::move(result->users_), "GetUserBoostsQuery");
auto total_count = result->count_;
vector<td_api::object_ptr<td_api::chatBoost>> boosts;
for (auto &boost : result->boosts_) {
auto chat_boost_object = get_chat_boost_object(td_, boost);
if (chat_boost_object == nullptr || chat_boost_object->expiration_date_ <= G()->unix_time()) {
continue;
}
boosts.push_back(std::move(chat_boost_object));
}
promise_.set_value(
td_api::make_object<td_api::foundChatBoosts>(total_count, std::move(boosts), result->next_offset_));
}
void on_error(Status status) final {
td_->messages_manager_->on_get_dialog_error(dialog_id_, status, "GetUserBoostsQuery");
promise_.set_error(std::move(status));
}
};
BoostManager::BoostManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
}
@ -376,7 +424,7 @@ td_api::object_ptr<td_api::chatBoostLinkInfo> BoostManager::get_chat_boost_link_
void BoostManager::get_dialog_boosts(DialogId dialog_id, bool only_gift_codes, const string &offset, int32 limit,
Promise<td_api::object_ptr<td_api::foundChatBoosts>> &&promise) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_dialog_boost_status")) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_dialog_boosts")) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Read)) {
@ -389,6 +437,21 @@ void BoostManager::get_dialog_boosts(DialogId dialog_id, bool only_gift_codes, c
td_->create_handler<GetBoostsListQuery>(std::move(promise))->send(dialog_id, only_gift_codes, offset, limit);
}
void BoostManager::get_user_dialog_boosts(DialogId dialog_id, UserId user_id,
Promise<td_api::object_ptr<td_api::foundChatBoosts>> &&promise) {
if (!td_->messages_manager_->have_dialog_force(dialog_id, "get_user_dialog_boosts")) {
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"));
}
if (!user_id.is_valid()) {
return promise.set_error(Status::Error(400, "User not found"));
}
td_->create_handler<GetUserBoostsQuery>(std::move(promise))->send(dialog_id, user_id);
}
void BoostManager::on_update_dialog_boost(DialogId dialog_id, telegram_api::object_ptr<telegram_api::boost> &&boost) {
if (!td_->auth_manager_->is_bot()) {
LOG(ERROR) << "Receive updateBotChatBoost by a non-bot";

View File

@ -43,6 +43,9 @@ class BoostManager final : public Actor {
void get_dialog_boosts(DialogId dialog_id, bool only_gift_codes, const string &offset, int32 limit,
Promise<td_api::object_ptr<td_api::foundChatBoosts>> &&promise);
void get_user_dialog_boosts(DialogId dialog_id, UserId user_id,
Promise<td_api::object_ptr<td_api::foundChatBoosts>> &&promise);
void on_update_dialog_boost(DialogId dialog_id, telegram_api::object_ptr<telegram_api::boost> &&boost);
private:

View File

@ -6674,6 +6674,12 @@ void Td::on_request(uint64 id, td_api::getChatBoosts &request) {
request.limit_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getUserChatBoosts &request) {
CHECK_IS_BOT();
CREATE_REQUEST_PROMISE();
boost_manager_->get_user_dialog_boosts(DialogId(request.chat_id_), UserId(request.user_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::getAttachmentMenuBot &request) {
CHECK_IS_USER();
CREATE_REQUEST_PROMISE();

View File

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

View File

@ -4365,6 +4365,11 @@ class CliClient final : public Actor {
string limit;
get_args(args, chat_id, only_gift_codes, offset, limit);
send_request(td_api::make_object<td_api::getChatBoosts>(chat_id, only_gift_codes, offset, as_limit(limit)));
} else if (op == "gucb") {
ChatId chat_id;
UserId user_id;
get_args(args, chat_id, user_id);
send_request(td_api::make_object<td_api::getUserChatBoosts>(chat_id, user_id));
} else if (op == "gamb") {
UserId user_id;
get_args(args, user_id);