Use dup_photo in dup_story_content.

This commit is contained in:
levlam 2024-06-25 00:33:37 +03:00
parent c304bb12d6
commit 031864db3e
2 changed files with 7 additions and 24 deletions

View File

@ -392,6 +392,8 @@ Result<Photo> create_photo(FileManager *file_manager, FileId file_id, PhotoSize
}
Photo dup_photo(Photo photo) {
CHECK(!photo.photos.empty());
// Find 'i' or largest
PhotoSize input_size;
for (const auto &size : photo.photos) {

View File

@ -429,31 +429,12 @@ unique_ptr<StoryContent> dup_story_content(Td *td, const StoryContent *content)
switch (content->get_type()) {
case StoryContentType::Photo: {
const auto *old_content = static_cast<const StoryContentPhoto *>(content);
// Find 'i' or largest
PhotoSize photo_size;
for (const auto &size : old_content->photo_.photos) {
if (size.type == 'i') {
photo_size = size;
}
auto photo = dup_photo(old_content->photo_);
photo.photos.back().file_id = fix_file_id(photo.photos.back().file_id);
if (photo.photos.size() > 1) {
photo.photos[0].file_id = fix_file_id(photo.photos[0].file_id);
}
if (photo_size.type == 0) {
for (const auto &size : old_content->photo_.photos) {
if (photo_size.type == 0 || photo_size < size) {
photo_size = size;
}
}
}
photo_size.type = 'i';
photo_size.file_id = fix_file_id(photo_size.file_id);
auto result = make_unique<StoryContentPhoto>(Photo(old_content->photo_));
result->photo_.photos.clear();
result->photo_.animations.clear();
result->photo_.sticker_photo_size = nullptr;
result->photo_.photos.push_back(std::move(photo_size));
return std::move(result);
return make_unique<StoryContentPhoto>(std::move(photo));
}
case StoryContentType::Video: {
const auto *old_content = static_cast<const StoryContentVideo *>(content);