From 6cf3755707389319cca0a3bd557499605ef43a30 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 31 Mar 2021 02:54:29 +0300 Subject: [PATCH] Improve get_input_bot_inline_message_media_* functions. --- td/telegram/Contact.cpp | 6 +++++- td/telegram/Contact.h | 2 +- td/telegram/InlineQueriesManager.cpp | 26 ++++++++++++++++---------- td/telegram/Payments.cpp | 8 ++++++-- td/telegram/Payments.h | 2 +- td/telegram/Venue.cpp | 6 +++++- td/telegram/Venue.h | 3 +-- 7 files changed, 35 insertions(+), 18 deletions(-) diff --git a/td/telegram/Contact.cpp b/td/telegram/Contact.cpp index f75af4567..e9388a66d 100644 --- a/td/telegram/Contact.cpp +++ b/td/telegram/Contact.cpp @@ -58,7 +58,11 @@ tl_object_ptr Contact::get_input_phone_contact( } tl_object_ptr Contact::get_input_bot_inline_message_media_contact( - int32 flags, tl_object_ptr &&reply_markup) const { + tl_object_ptr &&reply_markup) const { + int32 flags = 0; + if (reply_markup != nullptr) { + flags |= telegram_api::inputBotInlineMessageMediaContact::REPLY_MARKUP_MASK; + } return make_tl_object(flags, phone_number_, first_name_, last_name_, vcard_, std::move(reply_markup)); } diff --git a/td/telegram/Contact.h b/td/telegram/Contact.h index 5617f1bb1..5ab981018 100644 --- a/td/telegram/Contact.h +++ b/td/telegram/Contact.h @@ -57,7 +57,7 @@ class Contact { tl_object_ptr get_input_phone_contact(int64 client_id) const; tl_object_ptr get_input_bot_inline_message_media_contact( - int32 flags, tl_object_ptr &&reply_markup) const; + tl_object_ptr &&reply_markup) const; template void store(StorerT &storer) const { diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index a35d146be..96411055b 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -229,16 +229,15 @@ Result> InlineQueriesManager: } TRY_RESULT(reply_markup, get_reply_markup(std::move(reply_markup_ptr), true, true, false, true)); auto input_reply_markup = get_input_reply_markup(reply_markup); - int32 flags = 0; - if (input_reply_markup != nullptr) { - flags |= telegram_api::inputBotInlineMessageText::REPLY_MARKUP_MASK; - } auto constructor_id = input_message_content->get_id(); if (constructor_id == td_api::inputMessageText::ID) { TRY_RESULT(input_message_text, process_input_message_text(td_->contacts_manager_.get(), DialogId(), std::move(input_message_content), true)); - + int32 flags = 0; + if (input_reply_markup != nullptr) { + flags |= telegram_api::inputBotInlineMessageText::REPLY_MARKUP_MASK; + } if (input_message_text.disable_web_page_preview) { flags |= telegram_api::inputBotInlineMessageText::NO_WEBPAGE_MASK; } @@ -253,14 +252,18 @@ Result> InlineQueriesManager: } if (constructor_id == td_api::inputMessageContact::ID) { TRY_RESULT(contact, process_input_message_contact(std::move(input_message_content))); - return contact.get_input_bot_inline_message_media_contact(flags, std::move(input_reply_markup)); + return contact.get_input_bot_inline_message_media_contact(std::move(input_reply_markup)); } if (constructor_id == td_api::inputMessageInvoice::ID) { TRY_RESULT(input_invoice, process_input_message_invoice(std::move(input_message_content), td_)); - return get_input_bot_inline_message_media_invoice(input_invoice, flags, std::move(input_reply_markup), td_); + return get_input_bot_inline_message_media_invoice(input_invoice, std::move(input_reply_markup), td_); } if (constructor_id == td_api::inputMessageLocation::ID) { TRY_RESULT(location, process_input_message_location(std::move(input_message_content))); + int32 flags = 0; + if (input_reply_markup != nullptr) { + flags |= telegram_api::inputBotInlineMessageMediaGeo::REPLY_MARKUP_MASK; + } if (location.heading != 0) { flags |= telegram_api::inputBotInlineMessageMediaGeo::HEADING_MASK; } @@ -274,16 +277,19 @@ Result> InlineQueriesManager: } if (constructor_id == td_api::inputMessageVenue::ID) { TRY_RESULT(venue, process_input_message_venue(std::move(input_message_content))); - return venue.get_input_bot_inline_message_media_venue(flags, std::move(input_reply_markup)); + return venue.get_input_bot_inline_message_media_venue(std::move(input_reply_markup)); } if (constructor_id == allowed_media_content_id) { TRY_RESULT(caption, process_input_caption(td_->contacts_manager_.get(), DialogId(), extract_input_caption(input_message_content), true)); + int32 flags = 0; + if (input_reply_markup != nullptr) { + flags |= telegram_api::inputBotInlineMessageMediaAuto::REPLY_MARKUP_MASK; + } auto entities = get_input_message_entities(td_->contacts_manager_.get(), caption.entities, "get_inline_message"); if (!entities.empty()) { - flags |= telegram_api::inputBotInlineMessageText::ENTITIES_MASK; + flags |= telegram_api::inputBotInlineMessageMediaAuto::ENTITIES_MASK; } - return make_tl_object(flags, caption.text, std::move(entities), std::move(input_reply_markup)); } diff --git a/td/telegram/Payments.cpp b/td/telegram/Payments.cpp index 566892e73..c8e231613 100644 --- a/td/telegram/Payments.cpp +++ b/td/telegram/Payments.cpp @@ -862,10 +862,14 @@ tl_object_ptr get_input_media_invoice(const Inp } tl_object_ptr get_input_bot_inline_message_media_invoice( - const InputInvoice &input_invoice, int32 flags, tl_object_ptr &&reply_markup, Td *td) { + const InputInvoice &input_invoice, tl_object_ptr &&reply_markup, Td *td) { + int32 flags = 0; + if (reply_markup != nullptr) { + flags |= telegram_api::inputBotInlineMessageMediaInvoice::REPLY_MARKUP_MASK; + } auto input_web_document = get_input_web_document(td->file_manager_.get(), input_invoice.photo); if (input_web_document != nullptr) { - flags |= telegram_api::inputMediaInvoice::PHOTO_MASK; + flags |= telegram_api::inputBotInlineMessageMediaInvoice::PHOTO_MASK; } return make_tl_object( flags, input_invoice.title, input_invoice.description, std::move(input_web_document), diff --git a/td/telegram/Payments.h b/td/telegram/Payments.h index 813b81040..21230d383 100644 --- a/td/telegram/Payments.h +++ b/td/telegram/Payments.h @@ -135,7 +135,7 @@ tl_object_ptr get_message_invoice_object(const InputInvo tl_object_ptr get_input_media_invoice(const InputInvoice &input_invoice, Td *td); tl_object_ptr get_input_bot_inline_message_media_invoice( - const InputInvoice &input_invoice, int32 flags, tl_object_ptr &&reply_markup, Td *td); + const InputInvoice &input_invoice, tl_object_ptr &&reply_markup, Td *td); vector get_input_invoice_file_ids(const InputInvoice &input_invoice); diff --git a/td/telegram/Venue.cpp b/td/telegram/Venue.cpp index 1eee9828f..4d4d785b7 100644 --- a/td/telegram/Venue.cpp +++ b/td/telegram/Venue.cpp @@ -67,7 +67,11 @@ SecretInputMedia Venue::get_secret_input_media_venue() const { } tl_object_ptr Venue::get_input_bot_inline_message_media_venue( - int32 flags, tl_object_ptr &&reply_markup) const { + tl_object_ptr &&reply_markup) const { + int32 flags = 0; + if (reply_markup != nullptr) { + flags |= telegram_api::inputBotInlineMessageMediaVenue::REPLY_MARKUP_MASK; + } return make_tl_object( flags, location_.get_input_geo_point(), title_, address_, provider_, id_, type_, std::move(reply_markup)); } diff --git a/td/telegram/Venue.h b/td/telegram/Venue.h index 240c15821..7174deb14 100644 --- a/td/telegram/Venue.h +++ b/td/telegram/Venue.h @@ -54,9 +54,8 @@ class Venue { SecretInputMedia get_secret_input_media_venue() const; - // TODO very strange function tl_object_ptr get_input_bot_inline_message_media_venue( - int32 flags, tl_object_ptr &&reply_markup) const; + tl_object_ptr &&reply_markup) const; template void store(StorerT &storer) const {