Add and use dup_photo.

This commit is contained in:
levlam 2024-06-25 00:24:11 +03:00
parent f8bf2d5370
commit c304bb12d6
3 changed files with 52 additions and 42 deletions

View File

@ -6596,54 +6596,14 @@ unique_ptr<MessageContent> dup_message_content(Td *td, DialogId dialog_id, const
return std::move(result);
}
// Find 'i' or largest
PhotoSize photo;
for (const auto &size : result->photo.photos) {
if (size.type == 'i') {
photo = size;
}
}
if (photo.type == 0) {
for (const auto &size : result->photo.photos) {
if (photo.type == 0 || photo < size) {
photo = size;
}
}
}
// Find 't' or smallest
PhotoSize thumbnail;
for (const auto &size : result->photo.photos) {
if (size.type == 't') {
thumbnail = size;
}
}
if (thumbnail.type == 0) {
for (const auto &size : result->photo.photos) {
if (size.type != photo.type && (thumbnail.type == 0 || size < thumbnail)) {
thumbnail = size;
}
}
}
result->photo.photos.clear();
result->photo.animations.clear();
result->photo.sticker_photo_size = nullptr;
bool has_thumbnail = thumbnail.type != 0;
if (has_thumbnail) {
thumbnail.type = 't';
result->photo.photos.push_back(std::move(thumbnail));
}
photo.type = 'i';
result->photo.photos.push_back(std::move(photo));
result->photo = dup_photo(result->photo);
if (photo_has_input_media(td->file_manager_.get(), result->photo, to_secret, td->auth_manager_->is_bot())) {
return std::move(result);
}
result->photo.photos.back().file_id = fix_file_id(result->photo.photos.back().file_id);
if (has_thumbnail) {
if (result->photo.photos.size() > 1) {
result->photo.photos[0].file_id =
td->file_manager_->dup_file_id(result->photo.photos[0].file_id, "dup_message_content photo");
}

View File

@ -391,6 +391,54 @@ Result<Photo> create_photo(FileManager *file_manager, FileId file_id, PhotoSize
return std::move(photo);
}
Photo dup_photo(Photo photo) {
// Find 'i' or largest
PhotoSize input_size;
for (const auto &size : photo.photos) {
if (size.type == 'i') {
input_size = size;
}
}
if (input_size.type == 0) {
for (const auto &size : photo.photos) {
if (input_size.type == 0 || input_size < size) {
input_size = size;
}
}
}
// Find 't' or smallest
PhotoSize thumbnail;
for (const auto &size : photo.photos) {
if (size.type == 't') {
thumbnail = size;
}
}
if (thumbnail.type == 0) {
for (const auto &size : photo.photos) {
if (size.type != input_size.type && (thumbnail.type == 0 || size < thumbnail)) {
thumbnail = size;
}
}
}
Photo result;
result.id = std::move(photo.id);
result.date = photo.date;
result.minithumbnail = std::move(photo.minithumbnail);
result.has_stickers = photo.has_stickers;
result.sticker_file_ids = std::move(photo.sticker_file_ids);
if (thumbnail.type != 0) {
thumbnail.type = 't';
result.photos.push_back(std::move(thumbnail));
}
input_size.type = 'i';
result.photos.push_back(std::move(input_size));
return result;
}
tl_object_ptr<td_api::photo> get_photo_object(FileManager *file_manager, const Photo &photo) {
if (photo.is_empty()) {
return nullptr;

View File

@ -121,6 +121,8 @@ Photo get_web_document_photo(FileManager *file_manager, tl_object_ptr<telegram_a
Result<Photo> create_photo(FileManager *file_manager, FileId file_id, PhotoSize &&thumbnail, int32 width, int32 height,
vector<FileId> &&sticker_file_ids);
Photo dup_photo(Photo photo);
tl_object_ptr<td_api::photo> get_photo_object(FileManager *file_manager, const Photo &photo);
tl_object_ptr<td_api::chatPhoto> get_chat_photo_object(FileManager *file_manager, const Photo &photo);