Skip to content

Commit 26aaaf6

Browse files
committed
Add and use ReplyMarkup::has_buy_button.
1 parent afbfb4d commit 26aaaf6

4 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎td/telegram/InlineKeyboardButton.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ struct InlineKeyboardButton {
6262
InlineKeyboardButton clone(DialogId dialog_id, const MessageContentDupType &dup_type, bool is_via_bot,
6363
bool is_rich_message) const;
6464

65+
bool is_buy() const {
66+
return type == Type::Buy;
67+
}
68+
6569
bool is_disabled() const {
6670
return type == Type::Disabled;
6771
}

‎td/telegram/MessagesManager.cpp‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36601,9 +36601,7 @@ Result<MessagesManager::InvoiceMessageInfo> MessagesManager::get_invoice_message
3660136601
if (!m->message_id.is_server() || m->ephemeral_message != nullptr) {
3660236602
return Status::Error(400, "Wrong message identifier");
3660336603
}
36604-
if (m->reply_markup == nullptr || m->reply_markup->inline_keyboard.empty() ||
36605-
m->reply_markup->inline_keyboard[0].empty() ||
36606-
m->reply_markup->inline_keyboard[0][0].type != InlineKeyboardButton::Type::Buy) {
36604+
if (m->reply_markup == nullptr || !m->reply_markup->has_buy_button()) {
3660736605
if (content_type != MessageContentType::PaidMedia) {
3660836606
return Status::Error(400, "Message has no Pay button");
3660936607
}

‎td/telegram/ReplyMarkup.cpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,10 @@ const RequestedDialogType *ReplyMarkup::get_requested_dialog_type(int32 button_i
467467
return nullptr;
468468
}
469469

470+
bool ReplyMarkup::has_buy_button() const {
471+
return !inline_keyboard.empty() && !inline_keyboard[0].empty() && inline_keyboard[0][0].is_buy();
472+
}
473+
470474
bool ReplyMarkup::has_disabled_buttons() const {
471475
for (auto &row : inline_keyboard) {
472476
for (auto &button : row) {

‎td/telegram/ReplyMarkup.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ struct ReplyMarkup {
4747

4848
const RequestedDialogType *get_requested_dialog_type(int32 button_id) const;
4949

50+
bool has_buy_button() const;
51+
5052
bool has_disabled_buttons() const;
5153
};
5254

0 commit comments

Comments
 (0)