Move some functions to Photo.h.
This commit is contained in:
parent
e9b181ec42
commit
2a4201f989
@ -1226,14 +1226,7 @@ static void parse(unique_ptr<MessageContent> &content, ParserT &parser) {
|
||||
case MessageContentType::Photo: {
|
||||
auto m = make_unique<MessagePhoto>();
|
||||
parse(m->photo, parser);
|
||||
for (auto &photo_size : m->photo.photos) {
|
||||
if (!photo_size.file_id.is_valid()) {
|
||||
is_bad = true;
|
||||
}
|
||||
}
|
||||
if (m->photo.is_empty()) {
|
||||
is_bad = true;
|
||||
}
|
||||
is_bad |= m->photo.is_bad();
|
||||
parse_caption(m->caption, parser);
|
||||
content = std::move(m);
|
||||
break;
|
||||
@ -3678,6 +3671,7 @@ bool merge_message_content_file_id(Td *td, MessageContent *message_content, File
|
||||
return false;
|
||||
}
|
||||
|
||||
// secret chats only
|
||||
LOG(INFO) << "Merge message content of a message with file " << new_file_id;
|
||||
MessageContentType content_type = message_content->get_type();
|
||||
switch (content_type) {
|
||||
@ -5456,12 +5450,7 @@ FileId get_message_content_upload_file_id(const MessageContent *content) {
|
||||
case MessageContentType::Invoice:
|
||||
return get_input_invoice_upload_file_id(static_cast<const MessageInvoice *>(content)->input_invoice);
|
||||
case MessageContentType::Photo:
|
||||
for (auto &size : static_cast<const MessagePhoto *>(content)->photo.photos) {
|
||||
if (size.type == 'i') {
|
||||
return size.file_id;
|
||||
}
|
||||
}
|
||||
break;
|
||||
return get_photo_upload_file_id(static_cast<const MessagePhoto *>(content)->photo);
|
||||
case MessageContentType::Sticker:
|
||||
return static_cast<const MessageSticker *>(content)->file_id;
|
||||
case MessageContentType::Video:
|
||||
@ -5480,10 +5469,7 @@ FileId get_message_content_any_file_id(const MessageContent *content) {
|
||||
FileId result = get_message_content_upload_file_id(content);
|
||||
if (!result.is_valid()) {
|
||||
if (content->get_type() == MessageContentType::Photo) {
|
||||
const auto &sizes = static_cast<const MessagePhoto *>(content)->photo.photos;
|
||||
if (!sizes.empty()) {
|
||||
result = sizes.back().file_id;
|
||||
}
|
||||
result = get_photo_any_file_id(static_cast<const MessagePhoto *>(content)->photo);
|
||||
} else if (content->get_type() == MessageContentType::Invoice) {
|
||||
result = get_input_invoice_any_file_id(static_cast<const MessageInvoice *>(content)->input_invoice);
|
||||
}
|
||||
@ -5533,12 +5519,7 @@ FileId get_message_content_thumbnail_file_id(const MessageContent *content, cons
|
||||
case MessageContentType::Invoice:
|
||||
return get_input_invoice_thumbnail_file_id(td, static_cast<const MessageInvoice *>(content)->input_invoice);
|
||||
case MessageContentType::Photo:
|
||||
for (auto &size : static_cast<const MessagePhoto *>(content)->photo.photos) {
|
||||
if (size.type == 't') {
|
||||
return size.file_id;
|
||||
}
|
||||
}
|
||||
break;
|
||||
return get_photo_thumbnail_file_id(static_cast<const MessagePhoto *>(content)->photo);
|
||||
case MessageContentType::Sticker:
|
||||
return td->stickers_manager_->get_sticker_thumbnail_file_id(
|
||||
static_cast<const MessageSticker *>(content)->file_id);
|
||||
|
@ -176,12 +176,7 @@ FileId MessageExtendedMedia::get_upload_file_id() const {
|
||||
case Type::Preview:
|
||||
break;
|
||||
case Type::Photo:
|
||||
for (auto &size : photo_.photos) {
|
||||
if (size.type == 'i') {
|
||||
return size.file_id;
|
||||
}
|
||||
}
|
||||
break;
|
||||
return get_photo_upload_file_id(photo_);
|
||||
case Type::Video:
|
||||
return video_file_id_;
|
||||
default:
|
||||
@ -197,12 +192,8 @@ FileId MessageExtendedMedia::get_any_file_id() const {
|
||||
case Type::Unsupported:
|
||||
case Type::Preview:
|
||||
break;
|
||||
case Type::Photo: {
|
||||
if (!photo_.photos.empty()) {
|
||||
return photo_.photos.back().file_id;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Type::Photo:
|
||||
return get_photo_any_file_id(photo_);
|
||||
case Type::Video:
|
||||
return video_file_id_;
|
||||
default:
|
||||
@ -219,12 +210,7 @@ FileId MessageExtendedMedia::get_thumbnail_file_id(const Td *td) const {
|
||||
case Type::Preview:
|
||||
break;
|
||||
case Type::Photo:
|
||||
for (auto &size : photo_.photos) {
|
||||
if (size.type == 't') {
|
||||
return size.file_id;
|
||||
}
|
||||
}
|
||||
break;
|
||||
return get_photo_thumbnail_file_id(photo_);
|
||||
case Type::Video:
|
||||
return td->videos_manager_->get_video_thumbnail_file_id(video_file_id_);
|
||||
default:
|
||||
|
@ -95,14 +95,7 @@ void MessageExtendedMedia::parse(ParserT &parser) {
|
||||
bool is_bad = false;
|
||||
if (has_photo) {
|
||||
td::parse(photo_, parser);
|
||||
for (auto &photo_size : photo_.photos) {
|
||||
if (!photo_size.file_id.is_valid()) {
|
||||
is_bad = true;
|
||||
}
|
||||
}
|
||||
if (photo_.is_empty()) {
|
||||
is_bad = true;
|
||||
}
|
||||
is_bad = photo_.is_bad();
|
||||
}
|
||||
if (has_video) {
|
||||
Td *td = parser.context()->td().get_actor_unsafe();
|
||||
|
@ -517,6 +517,32 @@ vector<FileId> photo_get_file_ids(const Photo &photo) {
|
||||
return result;
|
||||
}
|
||||
|
||||
FileId get_photo_upload_file_id(const Photo &photo) {
|
||||
for (auto &size : photo.photos) {
|
||||
if (size.type == 'i') {
|
||||
return size.file_id;
|
||||
}
|
||||
}
|
||||
return FileId();
|
||||
}
|
||||
|
||||
FileId get_photo_any_file_id(const Photo &photo) {
|
||||
const auto &sizes = photo.photos;
|
||||
if (!sizes.empty()) {
|
||||
return sizes.back().file_id;
|
||||
}
|
||||
return FileId();
|
||||
}
|
||||
|
||||
FileId get_photo_thumbnail_file_id(const Photo &photo) {
|
||||
for (auto &size : photo.photos) {
|
||||
if (size.type == 't') {
|
||||
return size.file_id;
|
||||
}
|
||||
}
|
||||
return FileId();
|
||||
}
|
||||
|
||||
bool operator==(const Photo &lhs, const Photo &rhs) {
|
||||
return lhs.id.get() == rhs.id.get() && lhs.photos == rhs.photos && lhs.animations == rhs.animations;
|
||||
}
|
||||
|
@ -50,6 +50,18 @@ struct Photo {
|
||||
bool is_empty() const {
|
||||
return id.get() == -2;
|
||||
}
|
||||
|
||||
bool is_bad() const {
|
||||
if (is_empty()) {
|
||||
return true;
|
||||
}
|
||||
for (auto &photo_size : photos) {
|
||||
if (!photo_size.file_id.is_valid()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
ProfilePhoto get_profile_photo(FileManager *file_manager, UserId user_id, int64 user_access_hash,
|
||||
@ -95,6 +107,12 @@ void photo_delete_thumbnail(Photo &photo);
|
||||
|
||||
bool photo_has_input_media(FileManager *file_manager, const Photo &photo, bool is_secret, bool is_bot);
|
||||
|
||||
FileId get_photo_upload_file_id(const Photo &photo);
|
||||
|
||||
FileId get_photo_any_file_id(const Photo &photo);
|
||||
|
||||
FileId get_photo_thumbnail_file_id(const Photo &photo);
|
||||
|
||||
SecretInputMedia photo_get_secret_input_media(FileManager *file_manager, const Photo &photo,
|
||||
tl_object_ptr<telegram_api::InputEncryptedFile> input_file,
|
||||
const string &caption, BufferSlice thumbnail);
|
||||
|
Loading…
Reference in New Issue
Block a user