diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 26efdd8e3..6f7bb3d08 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -3181,6 +3181,16 @@ bool can_have_input_media(const Td *td, const MessageContent *content, bool is_s case MessageContentType::Giveaway: case MessageContentType::GiveawayWinners: return is_server; + case MessageContentType::PaidMedia: + if (is_server) { + return true; + } + for (const auto &media : static_cast(content)->media) { + if (!media.has_input_media()) { + return false; + } + } + return true; case MessageContentType::Unsupported: case MessageContentType::ChatCreate: case MessageContentType::ChatChangeTitle: @@ -3244,7 +3254,6 @@ bool can_have_input_media(const Td *td, const MessageContent *content, bool is_s case MessageContentType::Video: case MessageContentType::VideoNote: case MessageContentType::VoiceNote: - case MessageContentType::PaidMedia: return true; default: UNREACHABLE(); @@ -6579,9 +6588,16 @@ unique_ptr dup_message_content(Td *td, DialogId dialog_id, const if (type == MessageContentDupType::Copy || type == MessageContentDupType::ServerCopy) { return nullptr; } + CHECK(!to_secret); auto result = make_unique(*static_cast(content)); + if (replace_caption) { + result->caption = std::move(copy_options.new_caption); + } if (type != MessageContentDupType::Forward) { - // TODO support PaidMedia sending + for (auto &media : result->media) { + media = media.dup_to_send(td); + CHECK(!media.is_empty()); + } } return result; } diff --git a/td/telegram/MessageExtendedMedia.cpp b/td/telegram/MessageExtendedMedia.cpp index 4009bb5c1..6a2b95d6c 100644 --- a/td/telegram/MessageExtendedMedia.cpp +++ b/td/telegram/MessageExtendedMedia.cpp @@ -6,6 +6,7 @@ // #include "td/telegram/MessageExtendedMedia.h" +#include "td/telegram/AuthManager.h" #include "td/telegram/Dimensions.h" #include "td/telegram/Document.h" #include "td/telegram/DocumentsManager.h" @@ -325,6 +326,54 @@ void MessageExtendedMedia::update_file_id_remote(FileId file_id) { } } +MessageExtendedMedia MessageExtendedMedia::dup_to_send(Td *td) const { + switch (type_) { + case Type::Empty: + case Type::Unsupported: + case Type::Preview: + return {}; + case Type::Photo: { + MessageExtendedMedia result; + result.type_ = Type::Photo; + CHECK(!photo_.photos.empty()); + if (photo_.photos.size() > 2 || photo_.photos.back().type != 'i') { + // already sent photo + result.photo_ = photo_; + if (!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())) { + 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) { + result.photo_.photos[0].file_id = + td->file_manager_->dup_file_id(result.photo_.photos[0].file_id, "MessageExtendedMedia::dup_to_send 3"); + } + } + } + return result; + } + 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 { + 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_); + } + CHECK(result.video_file_id_.is_valid()); + return result; + } + default: + UNREACHABLE(); + return {}; + } +} + telegram_api::object_ptr MessageExtendedMedia::get_input_media( Td *td, tl_object_ptr input_file, tl_object_ptr input_thumbnail) const { diff --git a/td/telegram/MessageExtendedMedia.h b/td/telegram/MessageExtendedMedia.h index 7a14fd53e..e0485dee6 100644 --- a/td/telegram/MessageExtendedMedia.h +++ b/td/telegram/MessageExtendedMedia.h @@ -63,6 +63,10 @@ class MessageExtendedMedia { return type_ == Type::Empty; } + bool has_input_media() const { + return type_ == Type::Photo || type_ == Type::Video; + } + void update_from(const MessageExtendedMedia &old_extended_media); bool update_to(Td *td, telegram_api::object_ptr extended_media_ptr, @@ -98,6 +102,8 @@ class MessageExtendedMedia { void update_file_id_remote(FileId file_id); + MessageExtendedMedia dup_to_send(Td *td) const; + telegram_api::object_ptr get_input_media( Td *td, tl_object_ptr input_file, tl_object_ptr input_thumbnail) const;