Add and use MessageExtendedMedia::dup_to_send.
This commit is contained in:
parent
1f9062834c
commit
55ba5ba092
@ -3181,6 +3181,16 @@ bool can_have_input_media(const Td *td, const MessageContent *content, bool is_s
|
|||||||
case MessageContentType::Giveaway:
|
case MessageContentType::Giveaway:
|
||||||
case MessageContentType::GiveawayWinners:
|
case MessageContentType::GiveawayWinners:
|
||||||
return is_server;
|
return is_server;
|
||||||
|
case MessageContentType::PaidMedia:
|
||||||
|
if (is_server) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (const auto &media : static_cast<const MessagePaidMedia *>(content)->media) {
|
||||||
|
if (!media.has_input_media()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
case MessageContentType::Unsupported:
|
case MessageContentType::Unsupported:
|
||||||
case MessageContentType::ChatCreate:
|
case MessageContentType::ChatCreate:
|
||||||
case MessageContentType::ChatChangeTitle:
|
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::Video:
|
||||||
case MessageContentType::VideoNote:
|
case MessageContentType::VideoNote:
|
||||||
case MessageContentType::VoiceNote:
|
case MessageContentType::VoiceNote:
|
||||||
case MessageContentType::PaidMedia:
|
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
@ -6579,9 +6588,16 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
|
|||||||
if (type == MessageContentDupType::Copy || type == MessageContentDupType::ServerCopy) {
|
if (type == MessageContentDupType::Copy || type == MessageContentDupType::ServerCopy) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
CHECK(!to_secret);
|
||||||
auto result = make_unique<MessagePaidMedia>(*static_cast<const MessagePaidMedia *>(content));
|
auto result = make_unique<MessagePaidMedia>(*static_cast<const MessagePaidMedia *>(content));
|
||||||
|
if (replace_caption) {
|
||||||
|
result->caption = std::move(copy_options.new_caption);
|
||||||
|
}
|
||||||
if (type != MessageContentDupType::Forward) {
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
#include "td/telegram/MessageExtendedMedia.h"
|
#include "td/telegram/MessageExtendedMedia.h"
|
||||||
|
|
||||||
|
#include "td/telegram/AuthManager.h"
|
||||||
#include "td/telegram/Dimensions.h"
|
#include "td/telegram/Dimensions.h"
|
||||||
#include "td/telegram/Document.h"
|
#include "td/telegram/Document.h"
|
||||||
#include "td/telegram/DocumentsManager.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<telegram_api::InputMedia> MessageExtendedMedia::get_input_media(
|
telegram_api::object_ptr<telegram_api::InputMedia> MessageExtendedMedia::get_input_media(
|
||||||
Td *td, tl_object_ptr<telegram_api::InputFile> input_file,
|
Td *td, tl_object_ptr<telegram_api::InputFile> input_file,
|
||||||
tl_object_ptr<telegram_api::InputFile> input_thumbnail) const {
|
tl_object_ptr<telegram_api::InputFile> input_thumbnail) const {
|
||||||
|
@ -63,6 +63,10 @@ class MessageExtendedMedia {
|
|||||||
return type_ == Type::Empty;
|
return type_ == Type::Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool has_input_media() const {
|
||||||
|
return type_ == Type::Photo || type_ == Type::Video;
|
||||||
|
}
|
||||||
|
|
||||||
void update_from(const MessageExtendedMedia &old_extended_media);
|
void update_from(const MessageExtendedMedia &old_extended_media);
|
||||||
|
|
||||||
bool update_to(Td *td, telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media_ptr,
|
bool update_to(Td *td, telegram_api::object_ptr<telegram_api::MessageExtendedMedia> extended_media_ptr,
|
||||||
@ -98,6 +102,8 @@ class MessageExtendedMedia {
|
|||||||
|
|
||||||
void update_file_id_remote(FileId file_id);
|
void update_file_id_remote(FileId file_id);
|
||||||
|
|
||||||
|
MessageExtendedMedia dup_to_send(Td *td) const;
|
||||||
|
|
||||||
telegram_api::object_ptr<telegram_api::InputMedia> get_input_media(
|
telegram_api::object_ptr<telegram_api::InputMedia> get_input_media(
|
||||||
Td *td, tl_object_ptr<telegram_api::InputFile> input_file,
|
Td *td, tl_object_ptr<telegram_api::InputFile> input_file,
|
||||||
tl_object_ptr<telegram_api::InputFile> input_thumbnail) const;
|
tl_object_ptr<telegram_api::InputFile> input_thumbnail) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user