Add td_api::closeWebApp.

This commit is contained in:
levlam 2022-03-31 21:45:35 +03:00
parent 4384a832bb
commit c1aa1defbb
7 changed files with 56 additions and 5 deletions

View File

@ -4878,6 +4878,9 @@ sendWebAppData bot_user_id:int53 button_text:string data:string = Ok;
//@reply_to_message_id Identifier of the replied message for the message sent by the web app; 0 if none //@reply_to_message_id Identifier of the replied message for the message sent by the web app; 0 if none
openWebApp chat_id:int53 bot_user_id:int53 url:string from_bot_menu:Bool theme:themeParameters reply_to_message_id:int53 = WebAppInfo; openWebApp chat_id:int53 bot_user_id:int53 url:string from_bot_menu:Bool theme:themeParameters reply_to_message_id:int53 = WebAppInfo;
//@description Informs TDLib that a previously opened web app was closed @launch_id Identifier of web app launch, received from openWebApp
closeWebApp launch_id:int64 = Ok;
//@description Sets the result of interaction with a web app and sends corresponding message on behalf of the user to the chat from which the query originated; for bots only //@description Sets the result of interaction with a web app and sends corresponding message on behalf of the user to the chat from which the query originated; for bots only
//@web_app_query_id Identifier of the web app query //@web_app_query_id Identifier of the web app query
//@result The result of the query //@result The result of the query

View File

@ -31,6 +31,8 @@ namespace td {
class RequestWebViewQuery final : public Td::ResultHandler { class RequestWebViewQuery final : public Td::ResultHandler {
Promise<td_api::object_ptr<td_api::webAppInfo>> promise_; Promise<td_api::object_ptr<td_api::webAppInfo>> promise_;
DialogId dialog_id_; DialogId dialog_id_;
UserId bot_user_id_;
MessageId reply_to_message_id_;
bool from_attach_menu_ = false; bool from_attach_menu_ = false;
public: public:
@ -38,9 +40,12 @@ class RequestWebViewQuery final : public Td::ResultHandler {
: promise_(std::move(promise)) { : promise_(std::move(promise)) {
} }
void send(DialogId dialog_id, tl_object_ptr<telegram_api::InputUser> &&input_user, string &&url, bool from_bot_menu, void send(DialogId dialog_id, UserId bot_user_id, tl_object_ptr<telegram_api::InputUser> &&input_user, string &&url,
td_api::object_ptr<td_api::themeParameters> &&theme, MessageId reply_to_message_id, bool silent) { bool from_bot_menu, td_api::object_ptr<td_api::themeParameters> &&theme, MessageId reply_to_message_id,
bool silent) {
dialog_id_ = dialog_id; dialog_id_ = dialog_id;
bot_user_id_ = bot_user_id;
reply_to_message_id_ = reply_to_message_id;
int32 flags = 0; int32 flags = 0;
@ -89,6 +94,7 @@ class RequestWebViewQuery final : public Td::ResultHandler {
} }
auto ptr = result_ptr.move_as_ok(); auto ptr = result_ptr.move_as_ok();
td_->attach_menu_manager_->open_web_view(ptr->query_id_, dialog_id_, bot_user_id_, reply_to_message_id_);
promise_.set_value(td_api::make_object<td_api::webAppInfo>(ptr->query_id_, ptr->url_)); promise_.set_value(td_api::make_object<td_api::webAppInfo>(ptr->query_id_, ptr->url_));
} }
@ -432,8 +438,26 @@ void AttachMenuManager::request_web_view(DialogId dialog_id, UserId bot_user_id,
bool silent = td_->messages_manager_->get_dialog_silent_send_message(dialog_id); bool silent = td_->messages_manager_->get_dialog_silent_send_message(dialog_id);
td_->create_handler<RequestWebViewQuery>(std::move(promise)) td_->create_handler<RequestWebViewQuery>(std::move(promise))
->send(dialog_id, std::move(input_user), std::move(url), from_bot_menu, std::move(theme), reply_to_message_id, ->send(dialog_id, bot_user_id, std::move(input_user), std::move(url), from_bot_menu, std::move(theme),
silent); reply_to_message_id, silent);
}
void AttachMenuManager::open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id,
MessageId reply_to_message_id) {
if (query_id == 0) {
LOG(ERROR) << "Receive web app query identifier == 0";
return;
}
OpenedWebView opened_web_view;
opened_web_view.dialog_id_ = dialog_id;
opened_web_view.bot_user_id_ = bot_user_id;
opened_web_view.reply_to_message_id_ = reply_to_message_id;
opened_web_views_.emplace(query_id, std::move(opened_web_view));
}
void AttachMenuManager::close_web_view(int64 query_id, Promise<Unit> &&promise) {
opened_web_views_.erase(query_id);
promise.set_value(Unit());
} }
Result<AttachMenuManager::AttachMenuBot> AttachMenuManager::get_attach_menu_bot( Result<AttachMenuManager::AttachMenuBot> AttachMenuManager::get_attach_menu_bot(

View File

@ -17,6 +17,7 @@
#include "td/actor/PromiseFuture.h" #include "td/actor/PromiseFuture.h"
#include "td/utils/common.h" #include "td/utils/common.h"
#include "td/utils/FlatHashSet.h"
#include "td/utils/Status.h" #include "td/utils/Status.h"
namespace td { namespace td {
@ -33,6 +34,10 @@ class AttachMenuManager final : public Actor {
bool from_bot_menu, td_api::object_ptr<td_api::themeParameters> &&theme, bool from_bot_menu, td_api::object_ptr<td_api::themeParameters> &&theme,
Promise<td_api::object_ptr<td_api::webAppInfo>> &&promise); Promise<td_api::object_ptr<td_api::webAppInfo>> &&promise);
void open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id, MessageId reply_to_message_id);
void close_web_view(int64 query_id, Promise<Unit> &&promise);
void reload_attach_menu_bots(Promise<Unit> &&promise); void reload_attach_menu_bots(Promise<Unit> &&promise);
void get_attach_menu_bot(UserId user_id, Promise<td_api::object_ptr<td_api::attachMenuBot>> &&promise); void get_attach_menu_bot(UserId user_id, Promise<td_api::object_ptr<td_api::attachMenuBot>> &&promise);
@ -117,6 +122,13 @@ class AttachMenuManager final : public Actor {
bool is_inited_ = false; bool is_inited_ = false;
int64 hash_ = 0; int64 hash_ = 0;
vector<AttachMenuBot> attach_menu_bots_; vector<AttachMenuBot> attach_menu_bots_;
struct OpenedWebView {
DialogId dialog_id_;
UserId bot_user_id_;
MessageId reply_to_message_id_;
};
FlatHashMap<int64, OpenedWebView> opened_web_views_;
}; };
} // namespace td } // namespace td

View File

@ -442,7 +442,7 @@ static Result<KeyboardButton> get_keyboard_button(tl_object_ptr<td_api::keyboard
} }
case td_api::keyboardButtonTypeWebApp::ID: { case td_api::keyboardButtonTypeWebApp::ID: {
if (!request_buttons_allowed) { if (!request_buttons_allowed) {
return Status::Error(400, "Web view can be used in private chats only"); return Status::Error(400, "Web app can be used in private chats only");
} }
auto button_type = move_tl_object_as<td_api::keyboardButtonTypeWebApp>(button->type_); auto button_type = move_tl_object_as<td_api::keyboardButtonTypeWebApp>(button->type_);

View File

@ -7369,6 +7369,12 @@ void Td::on_request(uint64 id, td_api::openWebApp &request) {
request.from_bot_menu_, std::move(request.theme_), std::move(promise)); request.from_bot_menu_, std::move(request.theme_), std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::closeWebApp &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
attach_menu_manager_->close_web_view(request.launch_id_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::answerWebAppQuery &request) { void Td::on_request(uint64 id, td_api::answerWebAppQuery &request) {
CHECK_IS_BOT(); CHECK_IS_BOT();
CLEAN_INPUT_STRING(request.web_app_query_id_); CLEAN_INPUT_STRING(request.web_app_query_id_);

View File

@ -1161,6 +1161,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::openWebApp &request); void on_request(uint64 id, td_api::openWebApp &request);
void on_request(uint64 id, const td_api::closeWebApp &request);
void on_request(uint64 id, td_api::answerWebAppQuery &request); void on_request(uint64 id, td_api::answerWebAppQuery &request);
void on_request(uint64 id, td_api::getCallbackQueryAnswer &request); void on_request(uint64 id, td_api::getCallbackQueryAnswer &request);

View File

@ -3448,6 +3448,10 @@ class CliClient final : public Actor {
get_args(args, chat_id, bot_user_id, url, from_bot_menu, reply_to_message_id); get_args(args, chat_id, bot_user_id, url, from_bot_menu, reply_to_message_id);
send_request(td_api::make_object<td_api::openWebApp>(chat_id, bot_user_id, url, from_bot_menu, send_request(td_api::make_object<td_api::openWebApp>(chat_id, bot_user_id, url, from_bot_menu,
get_theme_parameters(), reply_to_message_id)); get_theme_parameters(), reply_to_message_id));
} else if (op == "cwa") {
int64 launch_id;
get_args(args, launch_id);
send_request(td_api::make_object<td_api::closeWebApp>(launch_id));
} else if (op == "sca") { } else if (op == "sca") {
ChatId chat_id; ChatId chat_id;
string message_thread_id; string message_thread_id;