Add getUserChatBoosts.

This commit is contained in:
levlam 2023-11-13 20:16:11 +03:00 committed by David Guillen Fandos
parent 121e2d8a18
commit 34f9b8a860
2 changed files with 57 additions and 4 deletions

View File

@ -312,6 +312,7 @@ bool Client::init_methods() {
methods_.emplace("unbanchatsenderchat", &Client::process_unban_chat_sender_chat_query); methods_.emplace("unbanchatsenderchat", &Client::process_unban_chat_sender_chat_query);
methods_.emplace("approvechatjoinrequest", &Client::process_approve_chat_join_request_query); methods_.emplace("approvechatjoinrequest", &Client::process_approve_chat_join_request_query);
methods_.emplace("declinechatjoinrequest", &Client::process_decline_chat_join_request_query); methods_.emplace("declinechatjoinrequest", &Client::process_decline_chat_join_request_query);
methods_.emplace("getuserchatboosts", &Client::process_get_user_chat_boosts_query);
methods_.emplace("getstickerset", &Client::process_get_sticker_set_query); methods_.emplace("getstickerset", &Client::process_get_sticker_set_query);
methods_.emplace("getcustomemojistickers", &Client::process_get_custom_emoji_stickers_query); methods_.emplace("getcustomemojistickers", &Client::process_get_custom_emoji_stickers_query);
methods_.emplace("uploadstickerfile", &Client::process_upload_sticker_file_query); methods_.emplace("uploadstickerfile", &Client::process_upload_sticker_file_query);
@ -3157,6 +3158,22 @@ class Client::JsonChatBoostRemoved final : public td::Jsonable {
const Client *client_; const Client *client_;
}; };
class Client::JsonChatBoosts final : public td::Jsonable {
public:
JsonChatBoosts(const td_api::foundChatBoosts *chat_boosts, const Client *client)
: chat_boosts_(chat_boosts), client_(client) {
}
void store(td::JsonValueScope *scope) const {
auto object = scope->enter_object();
object("boosts", td::json_array(chat_boosts_->boosts_,
[client = client_](auto &boost) { return JsonChatBoost(boost.get(), client); }));
}
private:
const td_api::foundChatBoosts *chat_boosts_;
const Client *client_;
};
class Client::JsonGameHighScore final : public td::Jsonable { class Client::JsonGameHighScore final : public td::Jsonable {
public: public:
JsonGameHighScore(const td_api::gameHighScore *score, const Client *client) : score_(score), client_(client) { JsonGameHighScore(const td_api::gameHighScore *score, const Client *client) : score_(score), client_(client) {
@ -4557,9 +4574,9 @@ class Client::TdOnGetSupergroupMembersCallback final : public TdQueryCallback {
PromisedQueryPtr query_; PromisedQueryPtr query_;
}; };
class Client::TdOnGetSupergroupMembersCountCallback final : public TdQueryCallback { class Client::TdOnGetSupergroupMemberCountCallback final : public TdQueryCallback {
public: public:
explicit TdOnGetSupergroupMembersCountCallback(PromisedQueryPtr query) : query_(std::move(query)) { explicit TdOnGetSupergroupMemberCountCallback(PromisedQueryPtr query) : query_(std::move(query)) {
} }
void on_result(object_ptr<td_api::Object> result) final { void on_result(object_ptr<td_api::Object> result) final {
@ -4683,6 +4700,26 @@ class Client::TdOnAnswerWebAppQueryCallback final : public TdQueryCallback {
PromisedQueryPtr query_; PromisedQueryPtr query_;
}; };
class Client::TdOnGetUserChatBoostsCallback final : public TdQueryCallback {
public:
TdOnGetUserChatBoostsCallback(Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) {
}
void on_result(object_ptr<td_api::Object> result) final {
if (result->get_id() == td_api::error::ID) {
return fail_query_with_error(std::move(query_), move_object_as<td_api::error>(result));
}
CHECK(result->get_id() == td_api::foundChatBoosts::ID);
auto chat_boosts = move_object_as<td_api::foundChatBoosts>(result);
answer_query(JsonChatBoosts(chat_boosts.get(), client_), std::move(query_));
}
private:
Client *client_;
PromisedQueryPtr query_;
};
class Client::TdOnReturnFileCallback final : public TdQueryCallback { class Client::TdOnReturnFileCallback final : public TdQueryCallback {
public: public:
TdOnReturnFileCallback(const Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) { TdOnReturnFileCallback(const Client *client, PromisedQueryPtr query) : client_(client), query_(std::move(query)) {
@ -10212,7 +10249,7 @@ td::Status Client::process_get_chat_member_count_query(PromisedQueryPtr &query)
} }
case ChatInfo::Type::Supergroup: case ChatInfo::Type::Supergroup:
return send_request(make_object<td_api::getSupergroupFullInfo>(chat_info->supergroup_id), return send_request(make_object<td_api::getSupergroupFullInfo>(chat_info->supergroup_id),
td::make_unique<TdOnGetSupergroupMembersCountCallback>(std::move(query))); td::make_unique<TdOnGetSupergroupMemberCountCallback>(std::move(query)));
case ChatInfo::Type::Unknown: case ChatInfo::Type::Unknown:
default: default:
UNREACHABLE(); UNREACHABLE();
@ -10474,6 +10511,19 @@ td::Status Client::process_decline_chat_join_request_query(PromisedQueryPtr &que
return td::Status::OK(); return td::Status::OK();
} }
td::Status Client::process_get_user_chat_boosts_query(PromisedQueryPtr &query) {
auto chat_id = query->arg("chat_id");
TRY_RESULT(user_id, get_user_id(query.get()));
check_chat(chat_id, AccessRights::Write, std::move(query), [this, user_id](int64 chat_id, PromisedQueryPtr query) {
check_user_no_fail(user_id, std::move(query), [this, chat_id, user_id](PromisedQueryPtr query) {
send_request(make_object<td_api::getUserChatBoosts>(chat_id, user_id),
td::make_unique<TdOnGetUserChatBoostsCallback>(this, std::move(query)));
});
});
return td::Status::OK();
}
td::Status Client::process_get_sticker_set_query(PromisedQueryPtr &query) { td::Status Client::process_get_sticker_set_query(PromisedQueryPtr &query) {
auto name = query->arg("name"); auto name = query->arg("name");
if (td::trim(to_lower(name)) == to_lower(GREAT_MINDS_SET_NAME)) { if (td::trim(to_lower(name)) == to_lower(GREAT_MINDS_SET_NAME)) {

View File

@ -163,6 +163,7 @@ class Client final : public WebhookActor::Callback {
class JsonChatBoost; class JsonChatBoost;
class JsonChatBoostUpdated; class JsonChatBoostUpdated;
class JsonChatBoostRemoved; class JsonChatBoostRemoved;
class JsonChatBoosts;
class JsonForumTopicCreated; class JsonForumTopicCreated;
class JsonForumTopicEdited; class JsonForumTopicEdited;
class JsonForumTopicInfo; class JsonForumTopicInfo;
@ -229,7 +230,8 @@ class Client final : public WebhookActor::Callback {
class TdOnGetChatPinnedMessageToUnpinCallback; class TdOnGetChatPinnedMessageToUnpinCallback;
class TdOnGetGroupMembersCallback; class TdOnGetGroupMembersCallback;
class TdOnGetSupergroupMembersCallback; class TdOnGetSupergroupMembersCallback;
class TdOnGetSupergroupMembersCountCallback; class TdOnGetSupergroupMemberCountCallback;
class TdOnGetUserChatBoostsCallback;
class TdOnCreateInvoiceLinkCallback; class TdOnCreateInvoiceLinkCallback;
class TdOnReplacePrimaryChatInviteLinkCallback; class TdOnReplacePrimaryChatInviteLinkCallback;
class TdOnGetChatInviteLinkCallback; class TdOnGetChatInviteLinkCallback;
@ -675,6 +677,7 @@ class Client final : public WebhookActor::Callback {
td::Status process_unban_chat_sender_chat_query(PromisedQueryPtr &query); td::Status process_unban_chat_sender_chat_query(PromisedQueryPtr &query);
td::Status process_approve_chat_join_request_query(PromisedQueryPtr &query); td::Status process_approve_chat_join_request_query(PromisedQueryPtr &query);
td::Status process_decline_chat_join_request_query(PromisedQueryPtr &query); td::Status process_decline_chat_join_request_query(PromisedQueryPtr &query);
td::Status process_get_user_chat_boosts_query(PromisedQueryPtr &query);
td::Status process_get_sticker_set_query(PromisedQueryPtr &query); td::Status process_get_sticker_set_query(PromisedQueryPtr &query);
td::Status process_get_custom_emoji_stickers_query(PromisedQueryPtr &query); td::Status process_get_custom_emoji_stickers_query(PromisedQueryPtr &query);
td::Status process_upload_sticker_file_query(PromisedQueryPtr &query); td::Status process_upload_sticker_file_query(PromisedQueryPtr &query);