Add getChatMenuButton.

This commit is contained in:
levlam 2022-04-08 03:07:52 +03:00
parent 2989274f1f
commit 84199e5328
2 changed files with 57 additions and 2 deletions

View File

@ -194,6 +194,7 @@ bool Client::init_methods() {
methods_.emplace("deletemycommands", &Client::process_delete_my_commands_query); methods_.emplace("deletemycommands", &Client::process_delete_my_commands_query);
methods_.emplace("getmydefaultadministratorrights", &Client::process_get_my_default_administrator_rights_query); methods_.emplace("getmydefaultadministratorrights", &Client::process_get_my_default_administrator_rights_query);
methods_.emplace("setmydefaultadministratorrights", &Client::process_set_my_default_administrator_rights_query); methods_.emplace("setmydefaultadministratorrights", &Client::process_set_my_default_administrator_rights_query);
methods_.emplace("getchatmenubutton", &Client::process_get_chat_menu_button_query);
methods_.emplace("getuserprofilephotos", &Client::process_get_user_profile_photos_query); methods_.emplace("getuserprofilephotos", &Client::process_get_user_profile_photos_query);
methods_.emplace("sendmessage", &Client::process_send_message_query); methods_.emplace("sendmessage", &Client::process_send_message_query);
methods_.emplace("sendanimation", &Client::process_send_animation_query); methods_.emplace("sendanimation", &Client::process_send_animation_query);
@ -2293,6 +2294,25 @@ class Client::JsonBotCommand final : public Jsonable {
const td_api::botCommand *command_; const td_api::botCommand *command_;
}; };
class Client::JsonBotMenuButton final : public Jsonable {
public:
explicit JsonBotMenuButton(const td_api::botMenuButton *menu_button) : menu_button_(menu_button) {
}
void store(JsonValueScope *scope) const {
auto object = scope->enter_object();
if (menu_button_->text_.empty()) {
object("type", menu_button_->url_.empty() ? "commands" : "default");
} else {
object("type", "web_app");
object("text", menu_button_->text_);
object("web_app", JsonWebAppInfo(menu_button_->url_));
}
}
private:
const td_api::botMenuButton *menu_button_;
};
class Client::JsonChatAdministratorRights final : public Jsonable { class Client::JsonChatAdministratorRights final : public Jsonable {
public: public:
JsonChatAdministratorRights(const td_api::chatAdministratorRights *rights, Client::ChatType chat_type) JsonChatAdministratorRights(const td_api::chatAdministratorRights *rights, Client::ChatType chat_type)
@ -3369,6 +3389,25 @@ class Client::TdOnGetMyDefaultAdministratorRightsCallback final : public TdQuery
PromisedQueryPtr query_; PromisedQueryPtr query_;
}; };
class Client::TdOnGetMenuButtonCallback final : public TdQueryCallback {
public:
explicit TdOnGetMenuButtonCallback(PromisedQueryPtr query) : 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::botMenuButton::ID);
auto menu_button = move_object_as<td_api::botMenuButton>(result);
answer_query(JsonBotMenuButton(menu_button.get()), std::move(query_));
}
private:
PromisedQueryPtr query_;
};
class Client::TdOnGetChatFullInfoCallback final : public TdQueryCallback { class Client::TdOnGetChatFullInfoCallback final : public TdQueryCallback {
public: public:
TdOnGetChatFullInfoCallback(Client *client, int64 chat_id, PromisedQueryPtr query) TdOnGetChatFullInfoCallback(Client *client, int64 chat_id, PromisedQueryPtr query)
@ -3860,7 +3899,7 @@ template <class OnSuccess>
void Client::check_user_read_access(const UserInfo *user_info, PromisedQueryPtr query, OnSuccess on_success) { void Client::check_user_read_access(const UserInfo *user_info, PromisedQueryPtr query, OnSuccess on_success) {
CHECK(user_info != nullptr); CHECK(user_info != nullptr);
if (!user_info->have_access) { if (!user_info->have_access) {
return fail_query(400, "Bad Request: have no access to the user", std::move(query)); // return fail_query(400, "Bad Request: have no access to the user", std::move(query));
} }
on_success(std::move(query)); on_success(std::move(query));
} }
@ -6793,6 +6832,19 @@ td::Status Client::process_set_my_default_administrator_rights_query(PromisedQue
return Status::OK(); return Status::OK();
} }
td::Status Client::process_get_chat_menu_button_query(PromisedQueryPtr &query) {
if (query->has_arg("chat_id")) {
TRY_RESULT(user_id, get_user_id(query.get(), "chat_id"));
check_user(user_id, std::move(query), [this, user_id](PromisedQueryPtr query) {
send_request(make_object<td_api::getMenuButton>(user_id),
td::make_unique<TdOnGetMenuButtonCallback>(std::move(query)));
});
} else {
send_request(make_object<td_api::getMenuButton>(0), td::make_unique<TdOnGetMenuButtonCallback>(std::move(query)));
}
return Status::OK();
}
td::Status Client::process_get_user_profile_photos_query(PromisedQueryPtr &query) { td::Status Client::process_get_user_profile_photos_query(PromisedQueryPtr &query) {
TRY_RESULT(user_id, get_user_id(query.get())); TRY_RESULT(user_id, get_user_id(query.get()));
int32 offset = get_integer_arg(query.get(), "offset", 0, 0); int32 offset = get_integer_arg(query.get(), "offset", 0, 0);

View File

@ -134,6 +134,7 @@ class Client final : public WebhookActor::Callback {
class JsonShippingQuery; class JsonShippingQuery;
class JsonPreCheckoutQuery; class JsonPreCheckoutQuery;
class JsonBotCommand; class JsonBotCommand;
class JsonBotMenuButton;
class JsonChatAdministratorRights; class JsonChatAdministratorRights;
class JsonChatPhotos; class JsonChatPhotos;
class JsonChatMember; class JsonChatMember;
@ -175,6 +176,7 @@ class Client final : public WebhookActor::Callback {
class TdOnGetEditedMessageCallback; class TdOnGetEditedMessageCallback;
class TdOnGetCallbackQueryMessageCallback; class TdOnGetCallbackQueryMessageCallback;
class TdOnGetStickerSetCallback; class TdOnGetStickerSetCallback;
class TdOnGetMenuButtonCallback;
class TdOnGetMyCommandsCallback; class TdOnGetMyCommandsCallback;
class TdOnGetMyDefaultAdministratorRightsCallback; class TdOnGetMyDefaultAdministratorRightsCallback;
class TdOnGetChatFullInfoCallback; class TdOnGetChatFullInfoCallback;
@ -454,9 +456,10 @@ class Client final : public WebhookActor::Callback {
Status process_get_me_query(PromisedQueryPtr &query); Status process_get_me_query(PromisedQueryPtr &query);
Status process_get_my_commands_query(PromisedQueryPtr &query); Status process_get_my_commands_query(PromisedQueryPtr &query);
Status process_set_my_commands_query(PromisedQueryPtr &query); Status process_set_my_commands_query(PromisedQueryPtr &query);
Status process_delete_my_commands_query(PromisedQueryPtr &query);
Status process_get_my_default_administrator_rights_query(PromisedQueryPtr &query); Status process_get_my_default_administrator_rights_query(PromisedQueryPtr &query);
Status process_set_my_default_administrator_rights_query(PromisedQueryPtr &query); Status process_set_my_default_administrator_rights_query(PromisedQueryPtr &query);
Status process_delete_my_commands_query(PromisedQueryPtr &query); Status process_get_chat_menu_button_query(PromisedQueryPtr &query);
Status process_get_user_profile_photos_query(PromisedQueryPtr &query); Status process_get_user_profile_photos_query(PromisedQueryPtr &query);
Status process_send_message_query(PromisedQueryPtr &query); Status process_send_message_query(PromisedQueryPtr &query);
Status process_send_animation_query(PromisedQueryPtr &query); Status process_send_animation_query(PromisedQueryPtr &query);