From 5cb008b58d674b945d374b33cc17d362ea909749 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 20 Jun 2024 19:01:21 +0300 Subject: [PATCH] Move caption out of ExtendedMedia. --- td/generate/scheme/td_api.tl | 20 ++++++++++---------- td/telegram/InputInvoice.cpp | 3 ++- td/telegram/MessageExtendedMedia.cpp | 21 +++++++++++++-------- td/telegram/MessageExtendedMedia.h | 5 +++-- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d21de80df..bd5ecb94f 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2790,17 +2790,16 @@ inputInvoiceTelegram purpose:TelegramPaymentPurpose = InputInvoice; //@height Media height; 0 if unknown //@duration Media duration, in seconds; 0 if unknown //@minithumbnail Media minithumbnail; may be null -//@caption Media caption -messageExtendedMediaPreview width:int32 height:int32 duration:int32 minithumbnail:minithumbnail caption:formattedText = MessageExtendedMedia; +messageExtendedMediaPreview width:int32 height:int32 duration:int32 minithumbnail:minithumbnail = MessageExtendedMedia; -//@description The media is a photo @photo The photo @caption Photo caption -messageExtendedMediaPhoto photo:photo caption:formattedText = MessageExtendedMedia; +//@description The media is a photo @photo The photo +messageExtendedMediaPhoto photo:photo = MessageExtendedMedia; -//@description The media is a video @video The video @caption Photo caption -messageExtendedMediaVideo video:video caption:formattedText = MessageExtendedMedia; +//@description The media is a video @video The video +messageExtendedMediaVideo video:video = MessageExtendedMedia; -//@description The media is unsupported @caption Media caption -messageExtendedMediaUnsupported caption:formattedText = MessageExtendedMedia; +//@description The media is unsupported +messageExtendedMediaUnsupported = MessageExtendedMedia; //@description Describes parameters of a Telegram Premium giveaway @@ -3200,8 +3199,9 @@ messageStory story_sender_chat_id:int53 story_id:int32 via_mention:Bool = Messag //@is_test True, if the invoice is a test invoice //@need_shipping_address True, if the shipping address must be specified //@receipt_message_id The identifier of the message with the receipt, after the product has been purchased -//@extended_media Extended media attached to the invoice; may be null -messageInvoice product_info:productInfo currency:string total_amount:int53 start_parameter:string is_test:Bool need_shipping_address:Bool receipt_message_id:int53 extended_media:MessageExtendedMedia = MessageContent; +//@extended_media Extended media attached to the invoice; may be null if none +//@extended_media_caption Extended media caption; may be null if none +messageInvoice product_info:productInfo currency:string total_amount:int53 start_parameter:string is_test:Bool need_shipping_address:Bool receipt_message_id:int53 extended_media:MessageExtendedMedia extended_media_caption:formattedText = MessageContent; //@description A message with information about an ended call @is_video True, if the call was a video call @discard_reason Reason why the call was discarded @duration Call duration, in seconds messageCall is_video:Bool discard_reason:CallDiscardReason duration:int32 = MessageContent; diff --git a/td/telegram/InputInvoice.cpp b/td/telegram/InputInvoice.cpp index 495119cab..10cb7697f 100644 --- a/td/telegram/InputInvoice.cpp +++ b/td/telegram/InputInvoice.cpp @@ -242,7 +242,8 @@ tl_object_ptr InputInvoice::get_message_invoice_object(T return make_tl_object( get_product_info_object(td, title_, description_, photo_), invoice_.currency_, total_amount_, start_parameter_, invoice_.is_test_, invoice_.need_shipping_address_, receipt_message_id_.get(), - extended_media_.get_message_extended_media_object(td, skip_bot_commands, max_media_timestamp)); + extended_media_.get_message_extended_media_object(td), + extended_media_.get_caption_object(skip_bot_commands, max_media_timestamp)); } tl_object_ptr InputInvoice::Invoice::get_input_invoice() const { diff --git a/td/telegram/MessageExtendedMedia.cpp b/td/telegram/MessageExtendedMedia.cpp index 8e079788f..f9d14f03d 100644 --- a/td/telegram/MessageExtendedMedia.cpp +++ b/td/telegram/MessageExtendedMedia.cpp @@ -152,34 +152,39 @@ bool MessageExtendedMedia::update_to(Td *td, return false; } -td_api::object_ptr MessageExtendedMedia::get_message_extended_media_object( - Td *td, bool skip_bot_commands, int32 max_media_timestamp) const { +td_api::object_ptr MessageExtendedMedia::get_message_extended_media_object(Td *td) const { if (type_ == Type::Empty) { return nullptr; } - auto caption = get_formatted_text_object(caption_, skip_bot_commands, max_media_timestamp); switch (type_) { case Type::Unsupported: - return td_api::make_object(std::move(caption)); + return td_api::make_object(); case Type::Preview: return td_api::make_object(dimensions_.width, dimensions_.height, duration_, - get_minithumbnail_object(minithumbnail_), - std::move(caption)); + get_minithumbnail_object(minithumbnail_)); case Type::Photo: { auto photo = get_photo_object(td->file_manager_.get(), photo_); CHECK(photo != nullptr); - return td_api::make_object(std::move(photo), std::move(caption)); + return td_api::make_object(std::move(photo)); } case Type::Video: return td_api::make_object( - td->videos_manager_->get_video_object(video_file_id_), std::move(caption)); + td->videos_manager_->get_video_object(video_file_id_)); default: UNREACHABLE(); return nullptr; } } +td_api::object_ptr MessageExtendedMedia::get_caption_object(bool skip_bot_commands, + int32 max_media_timestamp) const { + if (type_ == Type::Empty) { + return nullptr; + } + return get_formatted_text_object(caption_, skip_bot_commands, max_media_timestamp); +} + void MessageExtendedMedia::append_file_ids(const Td *td, vector &file_ids) const { switch (type_) { case Type::Empty: diff --git a/td/telegram/MessageExtendedMedia.h b/td/telegram/MessageExtendedMedia.h index ed488a1b7..a44a16de3 100644 --- a/td/telegram/MessageExtendedMedia.h +++ b/td/telegram/MessageExtendedMedia.h @@ -67,8 +67,9 @@ class MessageExtendedMedia { bool update_to(Td *td, telegram_api::object_ptr extended_media_ptr, DialogId owner_dialog_id); - td_api::object_ptr get_message_extended_media_object(Td *td, bool skip_bot_commands, - int32 max_media_timestamp) const; + td_api::object_ptr get_message_extended_media_object(Td *td) const; + + td_api::object_ptr get_caption_object(bool skip_bot_commands, int32 max_media_timestamp) const; void append_file_ids(const Td *td, vector &file_ids) const;