diff options
| author | levlam <levlam@telegram.org> | 2026-07-08 16:19:58 +0300 |
|---|---|---|
| committer | levlam <levlam@telegram.org> | 2026-07-08 16:19:58 +0300 |
| commit | 3c6baacea7ca25b76e0db1f2da775ecd1d9d7dff (patch) | |
| tree | 574efd026df79293b26bcaea4596a954d4a10d66 /td | |
| parent | d373fe382a239a7414201d93d920f8d344e7d2aa (diff) | |
Add RichMessageMedia::get_input_photo/get_input_document.
Diffstat (limited to 'td')
| -rw-r--r-- | td/telegram/RichMessageMedia.cpp | 40 | ||||
| -rw-r--r-- | td/telegram/RichMessageMedia.h | 7 |
2 files changed, 37 insertions, 10 deletions
diff --git a/td/telegram/RichMessageMedia.cpp b/td/telegram/RichMessageMedia.cpp index 10e965406..3d92b9172 100644 --- a/td/telegram/RichMessageMedia.cpp +++ b/td/telegram/RichMessageMedia.cpp @@ -6,6 +6,7 @@ // #include "td/telegram/RichMessageMedia.h" +#include "td/telegram/files/FileLocation.h" #include "td/telegram/files/FileManager.h" #include "td/telegram/MessageContentDupType.h" #include "td/telegram/MessageContentType.h" @@ -66,6 +67,33 @@ RichMessageMedia RichMessageMedia::clone(Td *td, DialogId dialog_id, const Messa return result; } +const FullRemoteFileLocation *RichMessageMedia::get_full_main_remote_location(const Td *td) const { + auto file_id = get_message_content_any_file_id(media_.get()); + CHECK(file_id.is_valid()); + auto file_view = td->file_manager_->get_file_view(file_id); + const auto *main_remote_location = file_view.get_main_remote_location(); + if (file_view.is_encrypted() || main_remote_location == nullptr || main_remote_location->is_web()) { + return nullptr; + } + return main_remote_location; +} + +telegram_api::object_ptr<telegram_api::InputPhoto> RichMessageMedia::get_input_photo(const Td *td) const { + const auto *main_remote_location = get_full_main_remote_location(td); + if (main_remote_location == nullptr) { + return nullptr; + } + return main_remote_location->as_input_photo(); +} + +telegram_api::object_ptr<telegram_api::InputDocument> RichMessageMedia::get_input_document(const Td *td) const { + const auto *main_remote_location = get_full_main_remote_location(td); + if (main_remote_location == nullptr) { + return nullptr; + } + return main_remote_location->as_input_document(); +} + telegram_api::object_ptr<telegram_api::InputRichFile> RichMessageMedia::get_input_rich_file( const Td *td, telegram_api::object_ptr<telegram_api::InputMedia> &&input_media) const { if (input_media != nullptr) { @@ -82,19 +110,11 @@ telegram_api::object_ptr<telegram_api::InputRichFile> RichMessageMedia::get_inpu UNREACHABLE(); } } - auto file_id = get_message_content_any_file_id(media_.get()); - CHECK(file_id.is_valid()); - auto file_view = td->file_manager_->get_file_view(file_id); - const auto *main_remote_location = file_view.get_main_remote_location(); - if (file_view.is_encrypted() || main_remote_location == nullptr || main_remote_location->is_web()) { - return nullptr; - } switch (media_->get_type()) { case MessageContentType::Photo: - return telegram_api::make_object<telegram_api::inputRichFilePhoto>(id_, main_remote_location->as_input_photo()); + return telegram_api::make_object<telegram_api::inputRichFilePhoto>(id_, get_input_photo(td)); default: - return telegram_api::make_object<telegram_api::inputRichFileDocument>(id_, - main_remote_location->as_input_document()); + return telegram_api::make_object<telegram_api::inputRichFileDocument>(id_, get_input_document(td)); } } diff --git a/td/telegram/RichMessageMedia.h b/td/telegram/RichMessageMedia.h index bad3b4a25..b52030ad9 100644 --- a/td/telegram/RichMessageMedia.h +++ b/td/telegram/RichMessageMedia.h @@ -17,12 +17,15 @@ namespace td { +class FullRemoteFileLocation; class Td; class RichMessageMedia { string id_; unique_ptr<MessageContent> media_; + const FullRemoteFileLocation *get_full_main_remote_location(const Td *td) const; + public: RichMessageMedia() = default; @@ -51,6 +54,10 @@ class RichMessageMedia { RichMessageMedia clone(Td *td, DialogId dialog_id, const MessageContentDupType &type) const; + telegram_api::object_ptr<telegram_api::InputPhoto> get_input_photo(const Td *td) const; + + telegram_api::object_ptr<telegram_api::InputDocument> get_input_document(const Td *td) const; + telegram_api::object_ptr<telegram_api::InputRichFile> get_input_rich_file( const Td *td, telegram_api::object_ptr<telegram_api::InputMedia> &&input_media) const; |
