From 224ec3301661284559a86d8a742a1726c3089468 Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 26 Jun 2024 13:32:08 +0300 Subject: [PATCH] Always dup paid media file identifiers if there are multiple files. --- td/telegram/MessageContent.cpp | 2 +- td/telegram/MessageExtendedMedia.cpp | 13 +++++++------ td/telegram/MessageExtendedMedia.h | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index a8cdae757..625cca035 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -6631,7 +6631,7 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const } if (type != MessageContentDupType::Forward) { for (auto &media : result->media) { - media = media.dup_to_send(td); + media = media.dup_to_send(td, result->media.size() > 1u); CHECK(!media.is_empty()); } } diff --git a/td/telegram/MessageExtendedMedia.cpp b/td/telegram/MessageExtendedMedia.cpp index ff14ad94f..3e259091d 100644 --- a/td/telegram/MessageExtendedMedia.cpp +++ b/td/telegram/MessageExtendedMedia.cpp @@ -326,7 +326,7 @@ void MessageExtendedMedia::update_file_id_remote(FileId file_id) { } } -MessageExtendedMedia MessageExtendedMedia::dup_to_send(Td *td) const { +MessageExtendedMedia MessageExtendedMedia::dup_to_send(Td *td, bool always_dup_files) const { switch (type_) { case Type::Empty: case Type::Unsupported: @@ -339,13 +339,14 @@ MessageExtendedMedia MessageExtendedMedia::dup_to_send(Td *td) const { if (photo_.photos.size() > 2 || photo_.photos.back().type != 'i') { // already sent photo result.photo_ = photo_; - if (!td->auth_manager_->is_bot()) { + if (always_dup_files || !td->auth_manager_->is_bot()) { result.photo_.photos.back().file_id = td->file_manager_->dup_file_id(result.photo_.photos.back().file_id, "MessageExtendedMedia::dup_to_send 1"); } } else { result.photo_ = dup_photo(photo_); - if (!photo_has_input_media(td->file_manager_.get(), result.photo_, false, td->auth_manager_->is_bot())) { + if (always_dup_files || + !photo_has_input_media(td->file_manager_.get(), result.photo_, false, td->auth_manager_->is_bot())) { result.photo_.photos.back().file_id = td->file_manager_->dup_file_id(result.photo_.photos.back().file_id, "MessageExtendedMedia::dup_to_send 2"); if (result.photo_.photos.size() > 1) { @@ -359,11 +360,11 @@ MessageExtendedMedia MessageExtendedMedia::dup_to_send(Td *td) const { case Type::Video: { MessageExtendedMedia result; result.type_ = Type::Video; - if (td->documents_manager_->has_input_media(video_file_id_, FileId(), false)) { - result.video_file_id_ = video_file_id_; - } else { + if (always_dup_files || !td->documents_manager_->has_input_media(video_file_id_, FileId(), false)) { result.video_file_id_ = td->videos_manager_->dup_video( td->file_manager_->dup_file_id(video_file_id_, "MessageExtendedMedia::dup_to_send 4"), video_file_id_); + } else { + result.video_file_id_ = video_file_id_; } CHECK(result.video_file_id_.is_valid()); return result; diff --git a/td/telegram/MessageExtendedMedia.h b/td/telegram/MessageExtendedMedia.h index eb07d9405..41d9ccb5e 100644 --- a/td/telegram/MessageExtendedMedia.h +++ b/td/telegram/MessageExtendedMedia.h @@ -102,7 +102,7 @@ class MessageExtendedMedia { void update_file_id_remote(FileId file_id); - MessageExtendedMedia dup_to_send(Td *td) const; + MessageExtendedMedia dup_to_send(Td *td, bool always_dup_files) const; telegram_api::object_ptr get_input_media( Td *td, tl_object_ptr input_file,