Remove openWebApp.from_bot_menu flag.

This commit is contained in:
levlam 2022-04-07 18:29:59 +03:00
parent e25ca7ef33
commit 00c64aba6e
8 changed files with 24 additions and 28 deletions

View File

@ -4894,10 +4894,9 @@ sendWebAppData bot_user_id:int53 button_text:string data:string = Ok;
//@chat_id Identifier of the chat in which the web app is opened. Web apps can be opened only in private chats for now
//@bot_user_id Identifier of the bot, providing the web app
//@url The URL from an inlineKeyboardButtonTypeWebApp button, a botMenuButton button, or an internalLinkTypeAttachMenuBot link, or an empty string otherwise
//@from_bot_menu Pass true if the web app is opened from bot menu
//@theme Preferred web app theme; pass null to use the default theme
//@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 theme:themeParameters reply_to_message_id:int53 = WebAppInfo;
//@description Informs TDLib that a previously opened web app was closed @web_app_launch_id Identifier of web app launch, received from openWebApp
closeWebApp web_app_launch_id:int64 = Ok;

View File

@ -42,8 +42,7 @@ class RequestWebViewQuery final : public Td::ResultHandler {
}
void send(DialogId dialog_id, UserId bot_user_id, tl_object_ptr<telegram_api::InputUser> &&input_user, string &&url,
bool from_bot_menu, td_api::object_ptr<td_api::themeParameters> &&theme, MessageId reply_to_message_id,
bool silent) {
td_api::object_ptr<td_api::themeParameters> &&theme, MessageId reply_to_message_id, bool silent) {
dialog_id_ = dialog_id;
bot_user_id_ = bot_user_id;
reply_to_message_id_ = reply_to_message_id;
@ -59,10 +58,12 @@ class RequestWebViewQuery final : public Td::ResultHandler {
url = string();
flags |= telegram_api::messages_requestWebView::START_PARAM_MASK;
} else if (begins_with(url, "menu://")) {
url = url.substr(7);
flags |= telegram_api::messages_requestWebView::FROM_BOT_MENU_MASK;
} else if (!url.empty()) {
flags |= telegram_api::messages_requestWebView::URL_MASK;
} else if (from_bot_menu) {
flags |= telegram_api::messages_requestWebView::FROM_BOT_MENU_MASK;
} else {
from_attach_menu_ = true;
}
@ -499,8 +500,7 @@ void AttachMenuManager::schedule_ping_web_view() {
}
void AttachMenuManager::request_web_view(DialogId dialog_id, UserId bot_user_id, MessageId reply_to_message_id,
string &&url, bool from_bot_menu,
td_api::object_ptr<td_api::themeParameters> &&theme,
string &&url, td_api::object_ptr<td_api::themeParameters> &&theme,
Promise<td_api::object_ptr<td_api::webAppInfo>> &&promise) {
TRY_STATUS_PROMISE(promise, td_->contacts_manager_->get_bot_data(bot_user_id));
TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(bot_user_id));
@ -522,10 +522,6 @@ void AttachMenuManager::request_web_view(DialogId dialog_id, UserId bot_user_id,
UNREACHABLE();
}
if (from_bot_menu && !url.empty()) {
return promise.set_error(Status::Error(400, "URL can't be specified when web app is opened from bot menu"));
}
if (!td_->messages_manager_->have_input_peer(dialog_id, AccessRights::Write)) {
return promise.set_error(Status::Error(400, "Have no write access to the chat"));
}
@ -538,8 +534,8 @@ void AttachMenuManager::request_web_view(DialogId dialog_id, UserId bot_user_id,
bool silent = td_->messages_manager_->get_dialog_silent_send_message(dialog_id);
td_->create_handler<RequestWebViewQuery>(std::move(promise))
->send(dialog_id, bot_user_id, std::move(input_user), std::move(url), from_bot_menu, std::move(theme),
reply_to_message_id, silent);
->send(dialog_id, bot_user_id, std::move(input_user), std::move(url), std::move(theme), reply_to_message_id,
silent);
}
void AttachMenuManager::open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id,

View File

@ -32,7 +32,7 @@ class AttachMenuManager final : public Actor {
void init();
void request_web_view(DialogId dialog_id, UserId bot_user_id, MessageId reply_to_message_id, string &&url,
bool from_bot_menu, td_api::object_ptr<td_api::themeParameters> &&theme,
td_api::object_ptr<td_api::themeParameters> &&theme,
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);

View File

@ -6,6 +6,7 @@
//
#include "td/telegram/BotMenuButton.h"
#include "td/telegram/AuthManager.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Global.h"
#include "td/telegram/LinkManager.h"
@ -69,7 +70,7 @@ class GetBotMenuButtonQuery final : public Td::ResultHandler {
auto bot_menu_button = get_bot_menu_button(result_ptr.move_as_ok());
promise_.set_value(bot_menu_button == nullptr ? td_api::make_object<td_api::botMenuButton>()
: bot_menu_button->get_bot_menu_button_object());
: bot_menu_button->get_bot_menu_button_object(td_));
}
void on_error(Status status) final {
@ -98,19 +99,20 @@ unique_ptr<BotMenuButton> get_bot_menu_button(telegram_api::object_ptr<telegram_
}
}
td_api::object_ptr<td_api::botMenuButton> BotMenuButton::get_bot_menu_button_object() const {
return td_api::make_object<td_api::botMenuButton>(text_, url_);
td_api::object_ptr<td_api::botMenuButton> BotMenuButton::get_bot_menu_button_object(Td *td) const {
bool is_bot = td->auth_manager_->is_bot();
return td_api::make_object<td_api::botMenuButton>(text_, is_bot ? url_ : "menu://" + url_);
}
bool operator==(const BotMenuButton &lhs, const BotMenuButton &rhs) {
return lhs.text_ == rhs.text_ && lhs.url_ == rhs.url_;
}
td_api::object_ptr<td_api::botMenuButton> get_bot_menu_button_object(const BotMenuButton *bot_menu_button) {
td_api::object_ptr<td_api::botMenuButton> get_bot_menu_button_object(Td *td, const BotMenuButton *bot_menu_button) {
if (bot_menu_button == nullptr) {
return nullptr;
}
return bot_menu_button->get_bot_menu_button_object();
return bot_menu_button->get_bot_menu_button_object(td);
}
void set_menu_button(Td *td, UserId user_id, td_api::object_ptr<td_api::botMenuButton> &&menu_button,

View File

@ -31,7 +31,7 @@ class BotMenuButton {
BotMenuButton(string &&text, string &&url) : text_(std::move(text)), url_(std::move(url)) {
}
td_api::object_ptr<td_api::botMenuButton> get_bot_menu_button_object() const;
td_api::object_ptr<td_api::botMenuButton> get_bot_menu_button_object(Td *td) const;
template <class StorerT>
void store(StorerT &storer) const {
@ -74,7 +74,7 @@ inline bool operator!=(const BotMenuButton &lhs, const BotMenuButton &rhs) {
unique_ptr<BotMenuButton> get_bot_menu_button(telegram_api::object_ptr<telegram_api::BotMenuButton> &&bot_menu_button);
td_api::object_ptr<td_api::botMenuButton> get_bot_menu_button_object(const BotMenuButton *bot_menu_button);
td_api::object_ptr<td_api::botMenuButton> get_bot_menu_button_object(Td *td, const BotMenuButton *bot_menu_button);
void set_menu_button(Td *td, UserId user_id, td_api::object_ptr<td_api::botMenuButton> &&menu_button,
Promise<Unit> &&promise);

View File

@ -16356,7 +16356,7 @@ tl_object_ptr<td_api::userFullInfo> ContactsManager::get_user_full_info_object(U
td_api::object_ptr<td_api::botInfo> bot_info;
bool is_bot = is_user_bot(user_id);
if (is_bot) {
auto menu_button = get_bot_menu_button_object(user_full->menu_button.get());
auto menu_button = get_bot_menu_button_object(td_, user_full->menu_button.get());
auto commands =
transform(user_full->commands, [](const auto &command) { return command.get_bot_command_object(); });
bot_info = td_api::make_object<td_api::botInfo>(

View File

@ -7404,7 +7404,7 @@ void Td::on_request(uint64 id, td_api::openWebApp &request) {
CREATE_REQUEST_PROMISE();
attach_menu_manager_->request_web_view(DialogId(request.chat_id_), UserId(request.bot_user_id_),
MessageId(request.reply_to_message_id_), std::move(request.url_),
request.from_bot_menu_, std::move(request.theme_), std::move(promise));
std::move(request.theme_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::closeWebApp &request) {

View File

@ -3443,11 +3443,10 @@ class CliClient final : public Actor {
ChatId chat_id;
UserId bot_user_id;
string url;
bool from_bot_menu;
MessageId 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,
get_theme_parameters(), reply_to_message_id));
get_args(args, chat_id, bot_user_id, url, reply_to_message_id);
send_request(td_api::make_object<td_api::openWebApp>(chat_id, bot_user_id, url, get_theme_parameters(),
reply_to_message_id));
} else if (op == "cwa") {
int64 launch_id;
get_args(args, launch_id);