Disallow switch_inline_query in channels.

GitOrigin-RevId: ad18c78f9abf4114ae72229f1b2f863f13ccba7a
This commit is contained in:
levlam 2018-11-05 14:29:43 +03:00
parent b1d563719a
commit 34a26188c6
3 changed files with 10 additions and 9 deletions

View File

@ -16715,11 +16715,11 @@ Result<unique_ptr<ReplyMarkup>> MessagesManager::get_dialog_reply_markup(
bool only_inline_keyboard = is_broadcast; bool only_inline_keyboard = is_broadcast;
bool request_buttons_allowed = dialog_type == DialogType::User; bool request_buttons_allowed = dialog_type == DialogType::User;
bool switch_inline_current_chat_buttons_allowed = !is_broadcast; bool switch_inline_buttons_allowed = !is_broadcast;
TRY_RESULT(reply_markup, TRY_RESULT(reply_markup,
get_reply_markup(std::move(reply_markup_ptr), td_->auth_manager_->is_bot(), only_inline_keyboard, get_reply_markup(std::move(reply_markup_ptr), td_->auth_manager_->is_bot(), only_inline_keyboard,
request_buttons_allowed, switch_inline_current_chat_buttons_allowed)); request_buttons_allowed, switch_inline_buttons_allowed));
if (reply_markup == nullptr) { if (reply_markup == nullptr) {
return nullptr; return nullptr;
} }

View File

@ -345,7 +345,7 @@ static Result<KeyboardButton> get_keyboard_button(tl_object_ptr<td_api::keyboard
} }
static Result<InlineKeyboardButton> get_inline_keyboard_button(tl_object_ptr<td_api::inlineKeyboardButton> &&button, static Result<InlineKeyboardButton> get_inline_keyboard_button(tl_object_ptr<td_api::inlineKeyboardButton> &&button,
bool switch_inline_current_chat_buttons_allowed) { bool switch_inline_buttons_allowed) {
CHECK(button != nullptr); CHECK(button != nullptr);
if (!clean_input_string(button->text_)) { if (!clean_input_string(button->text_)) {
return Status::Error(400, "Keyboard button text must be encoded in UTF-8"); return Status::Error(400, "Keyboard button text must be encoded in UTF-8");
@ -379,8 +379,10 @@ static Result<InlineKeyboardButton> get_inline_keyboard_button(tl_object_ptr<td_
break; break;
case td_api::inlineKeyboardButtonTypeSwitchInline::ID: { case td_api::inlineKeyboardButtonTypeSwitchInline::ID: {
auto switch_inline_button = move_tl_object_as<td_api::inlineKeyboardButtonTypeSwitchInline>(button->type_); auto switch_inline_button = move_tl_object_as<td_api::inlineKeyboardButtonTypeSwitchInline>(button->type_);
if (!switch_inline_current_chat_buttons_allowed && switch_inline_button->in_current_chat_) { if (!switch_inline_buttons_allowed) {
return Status::Error(400, "Can't use switch_inline_query_current_chat in a channel chat"); const char *button_name =
switch_inline_button->in_current_chat_ ? "switch_inline_query_current_chat" : "switch_inline_query";
return Status::Error(400, PSLICE() << "Can't use " << button_name << " in a channel chat");
} }
current_button.type = switch_inline_button->in_current_chat_ current_button.type = switch_inline_button->in_current_chat_
@ -404,7 +406,7 @@ static Result<InlineKeyboardButton> get_inline_keyboard_button(tl_object_ptr<td_
Result<unique_ptr<ReplyMarkup>> get_reply_markup(tl_object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr, bool is_bot, Result<unique_ptr<ReplyMarkup>> get_reply_markup(tl_object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr, bool is_bot,
bool only_inline_keyboard, bool request_buttons_allowed, bool only_inline_keyboard, bool request_buttons_allowed,
bool switch_inline_current_chat_buttons_allowed) { bool switch_inline_buttons_allowed) {
CHECK(!only_inline_keyboard || !request_buttons_allowed); CHECK(!only_inline_keyboard || !request_buttons_allowed);
if (reply_markup_ptr == nullptr || !is_bot) { if (reply_markup_ptr == nullptr || !is_bot) {
return nullptr; return nullptr;
@ -473,8 +475,7 @@ Result<unique_ptr<ReplyMarkup>> get_reply_markup(tl_object_ptr<td_api::ReplyMark
continue; continue;
} }
TRY_RESULT(current_button, TRY_RESULT(current_button, get_inline_keyboard_button(std::move(button), switch_inline_buttons_allowed));
get_inline_keyboard_button(std::move(button), switch_inline_current_chat_buttons_allowed));
row_buttons.push_back(std::move(current_button)); row_buttons.push_back(std::move(current_button));
row_button_count++; row_button_count++;

View File

@ -60,7 +60,7 @@ unique_ptr<ReplyMarkup> get_reply_markup(tl_object_ptr<telegram_api::ReplyMarkup
Result<unique_ptr<ReplyMarkup>> get_reply_markup(tl_object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr, bool is_bot, Result<unique_ptr<ReplyMarkup>> get_reply_markup(tl_object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr, bool is_bot,
bool only_inline_keyboard, bool request_buttons_allowed, bool only_inline_keyboard, bool request_buttons_allowed,
bool switch_inline_current_chat_buttons_allowed) TD_WARN_UNUSED_RESULT; bool switch_inline_buttons_allowed) TD_WARN_UNUSED_RESULT;
tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup(const unique_ptr<ReplyMarkup> &reply_markup); tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup(const unique_ptr<ReplyMarkup> &reply_markup);