From 031864db3e3c73778e146bdc50a23f44cb4d735c Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 25 Jun 2024 00:33:37 +0300 Subject: [PATCH] Use dup_photo in dup_story_content. --- td/telegram/Photo.cpp | 2 ++ td/telegram/StoryContent.cpp | 29 +++++------------------------ 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index c6bd8db46..88a369cbd 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -392,6 +392,8 @@ Result 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) { diff --git a/td/telegram/StoryContent.cpp b/td/telegram/StoryContent.cpp index 04be2715b..a76093128 100644 --- a/td/telegram/StoryContent.cpp +++ b/td/telegram/StoryContent.cpp @@ -429,31 +429,12 @@ unique_ptr dup_story_content(Td *td, const StoryContent *content) switch (content->get_type()) { case StoryContentType::Photo: { const auto *old_content = static_cast(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(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(std::move(photo)); } case StoryContentType::Video: { const auto *old_content = static_cast(content);