aboutsummaryrefslogtreecommitdiffhomepage
path: root/td
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2026-07-08 16:51:05 +0300
committerlevlam <levlam@telegram.org>2026-07-08 16:51:05 +0300
commit4b678b036d8a7a8b18001083c82d01f38beeb410 (patch)
treedf82de94d8e89fa6b8b2f89c897e170ceae01b00 /td
parent496950bd39a53cd87415bd6026745696982b64e7 (diff)
Use RichMessageMedia to get input page blocks.
Diffstat (limited to 'td')
-rw-r--r--td/telegram/RichMessage.cpp1
-rw-r--r--td/telegram/RichMessageMedia.cpp4
-rw-r--r--td/telegram/RichMessageMedia.h4
-rw-r--r--td/telegram/WebPageBlock.cpp60
-rw-r--r--td/telegram/WebPageBlock.h2
5 files changed, 38 insertions, 33 deletions
diff --git a/td/telegram/RichMessage.cpp b/td/telegram/RichMessage.cpp
index 72e017c56..1f845d7d2 100644
--- a/td/telegram/RichMessage.cpp
+++ b/td/telegram/RichMessage.cpp
@@ -247,6 +247,7 @@ telegram_api::object_ptr<telegram_api::InputRichMessage> RichMessage::get_input_
vector<telegram_api::object_ptr<telegram_api::PageBlock>> blocks;
GetInputPageBlockContext context;
context.td_ = td;
+ context.media_ = &media_;
for (const auto &block : blocks_) {
blocks.push_back(block->get_input_page_block(context));
}
diff --git a/td/telegram/RichMessageMedia.cpp b/td/telegram/RichMessageMedia.cpp
index 3d92b9172..2832364d1 100644
--- a/td/telegram/RichMessageMedia.cpp
+++ b/td/telegram/RichMessageMedia.cpp
@@ -78,7 +78,7 @@ const FullRemoteFileLocation *RichMessageMedia::get_full_main_remote_location(co
return main_remote_location;
}
-telegram_api::object_ptr<telegram_api::InputPhoto> RichMessageMedia::get_input_photo(const Td *td) const {
+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;
@@ -86,7 +86,7 @@ telegram_api::object_ptr<telegram_api::InputPhoto> RichMessageMedia::get_input_p
return main_remote_location->as_input_photo();
}
-telegram_api::object_ptr<telegram_api::InputDocument> RichMessageMedia::get_input_document(const Td *td) const {
+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;
diff --git a/td/telegram/RichMessageMedia.h b/td/telegram/RichMessageMedia.h
index b52030ad9..b0eea7f26 100644
--- a/td/telegram/RichMessageMedia.h
+++ b/td/telegram/RichMessageMedia.h
@@ -54,9 +54,9 @@ 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::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::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;
diff --git a/td/telegram/WebPageBlock.cpp b/td/telegram/WebPageBlock.cpp
index 0e069eb64..655ce437a 100644
--- a/td/telegram/WebPageBlock.cpp
+++ b/td/telegram/WebPageBlock.cpp
@@ -2499,12 +2499,13 @@ class WebPageBlockAnimation final : public WebPageBlock {
}
telegram_api::object_ptr<telegram_api::PageBlock> get_input_page_block(InputContext &context) const final {
- auto file_view = context.td_->file_manager_->get_file_view(animation_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()) {
- context.documents_.push_back(main_remote_location->as_input_document());
- return telegram_api::make_object<telegram_api::pageBlockVideo>(
- 0, need_autoplay, true, has_spoiler, main_remote_location->get_id(), caption.get_input_page_caption(context));
+ CHECK(context.media_ != nullptr && context.media_pos_ < context.media_->size());
+ auto input_document = (*context.media_)[context.media_pos_++].get_input_document(context.td_);
+ if (input_document != nullptr) {
+ auto id = input_document->id_;
+ context.documents_.push_back(std::move(input_document));
+ return telegram_api::make_object<telegram_api::pageBlockVideo>(0, need_autoplay, true, has_spoiler, id,
+ caption.get_input_page_caption(context));
}
LOG(INFO) << "Can't create pageBlockVideo for animation " << animation_file_id;
return telegram_api::make_object<telegram_api::pageBlockDivider>();
@@ -2622,12 +2623,13 @@ class WebPageBlockPhoto final : public WebPageBlock {
}
telegram_api::object_ptr<telegram_api::PageBlock> get_input_page_block(InputContext &context) const final {
- auto file_view = context.td_->file_manager_->get_file_view(get_photo_any_file_id(photo));
- 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()) {
- context.photos_.push_back(main_remote_location->as_input_photo());
+ CHECK(context.media_ != nullptr && context.media_pos_ < context.media_->size());
+ auto input_photo = (*context.media_)[context.media_pos_++].get_input_photo(context.td_);
+ if (input_photo != nullptr) {
+ auto id = input_photo->id_;
+ context.photos_.push_back(std::move(input_photo));
return telegram_api::make_object<telegram_api::pageBlockPhoto>(
- 0, has_spoiler, main_remote_location->get_id(), caption.get_input_page_caption(context), string(), 0);
+ 0, has_spoiler, id, caption.get_input_page_caption(context), string(), 0);
}
LOG(INFO) << "Can't create pageBlockPhoto for " << photo;
return telegram_api::make_object<telegram_api::pageBlockDivider>();
@@ -2735,12 +2737,12 @@ class WebPageBlockVideo final : public WebPageBlock {
}
telegram_api::object_ptr<telegram_api::PageBlock> get_input_page_block(InputContext &context) const final {
- auto file_view = context.td_->file_manager_->get_file_view(video_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()) {
- context.documents_.push_back(main_remote_location->as_input_document());
- return telegram_api::make_object<telegram_api::pageBlockVideo>(0, need_autoplay, is_looped, has_spoiler,
- main_remote_location->get_id(),
+ CHECK(context.media_ != nullptr && context.media_pos_ < context.media_->size());
+ auto input_document = (*context.media_)[context.media_pos_++].get_input_document(context.td_);
+ if (input_document != nullptr) {
+ auto id = input_document->id_;
+ context.documents_.push_back(std::move(input_document));
+ return telegram_api::make_object<telegram_api::pageBlockVideo>(0, need_autoplay, is_looped, has_spoiler, id,
caption.get_input_page_caption(context));
}
LOG(INFO) << "Can't create pageBlockVideo for video " << video_file_id;
@@ -3420,12 +3422,12 @@ class WebPageBlockAudio final : public WebPageBlock {
}
telegram_api::object_ptr<telegram_api::PageBlock> get_input_page_block(InputContext &context) const final {
- auto file_view = context.td_->file_manager_->get_file_view(audio_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()) {
- context.documents_.push_back(main_remote_location->as_input_document());
- return telegram_api::make_object<telegram_api::pageBlockAudio>(main_remote_location->get_id(),
- caption.get_input_page_caption(context));
+ CHECK(context.media_ != nullptr && context.media_pos_ < context.media_->size());
+ auto input_document = (*context.media_)[context.media_pos_++].get_input_document(context.td_);
+ if (input_document != nullptr) {
+ auto id = input_document->id_;
+ context.documents_.push_back(std::move(input_document));
+ return telegram_api::make_object<telegram_api::pageBlockAudio>(id, caption.get_input_page_caption(context));
}
LOG(INFO) << "Can't create pageBlockAudio for audio " << audio_file_id;
return telegram_api::make_object<telegram_api::pageBlockDivider>();
@@ -3972,12 +3974,12 @@ class WebPageBlockVoiceNote final : public WebPageBlock {
}
telegram_api::object_ptr<telegram_api::PageBlock> get_input_page_block(InputContext &context) const final {
- auto file_view = context.td_->file_manager_->get_file_view(voice_note_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()) {
- context.documents_.push_back(main_remote_location->as_input_document());
- return telegram_api::make_object<telegram_api::pageBlockAudio>(main_remote_location->get_id(),
- caption.get_input_page_caption(context));
+ CHECK(context.media_ != nullptr && context.media_pos_ < context.media_->size());
+ auto input_document = (*context.media_)[context.media_pos_++].get_input_document(context.td_);
+ if (input_document != nullptr) {
+ auto id = input_document->id_;
+ context.documents_.push_back(std::move(input_document));
+ return telegram_api::make_object<telegram_api::pageBlockAudio>(id, caption.get_input_page_caption(context));
}
LOG(INFO) << "Can't create pageBlockAudio for voice note " << voice_note_file_id;
return telegram_api::make_object<telegram_api::pageBlockDivider>();
diff --git a/td/telegram/WebPageBlock.h b/td/telegram/WebPageBlock.h
index a5b42b594..62beeda49 100644
--- a/td/telegram/WebPageBlock.h
+++ b/td/telegram/WebPageBlock.h
@@ -36,6 +36,8 @@ struct GetInputPageBlockContext {
const Td *td_ = nullptr;
vector<telegram_api::object_ptr<telegram_api::InputPhoto>> photos_;
vector<telegram_api::object_ptr<telegram_api::InputDocument>> documents_;
+ const vector<RichMessageMedia> *media_ = nullptr;
+ size_t media_pos_ = 0;
};
class WebPageBlock {