diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 02a794f3..51f0a8b4 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -390,6 +390,15 @@ tl_object_ptr get_photo_size_object(FileManager *file_manager file_manager->get_file_object(photo_size->file_id), photo_size->dimensions.width, photo_size->dimensions.height); } +void sort_photo_sizes(vector> &sizes) { + std::sort(sizes.begin(), sizes.end(), [](const auto &lhs, const auto &rhs) { + if (lhs->photo_->expected_size_ != rhs->photo_->expected_size_) { + return lhs->photo_->expected_size_ < rhs->photo_->expected_size_; + } + return lhs->width_ * lhs->height_ < rhs->width_ * rhs->height_; + }); +} + bool operator==(const PhotoSize &lhs, const PhotoSize &rhs) { return lhs.type == rhs.type && lhs.dimensions == rhs.dimensions && lhs.size == rhs.size && lhs.file_id == rhs.file_id; } @@ -454,13 +463,7 @@ tl_object_ptr get_photo_object(FileManager *file_manager, const P for (auto &photo_size : photo->photos) { photos.push_back(get_photo_size_object(file_manager, &photo_size)); } - std::sort(photos.begin(), photos.end(), [](const auto &lhs, const auto &rhs) { - if (lhs->photo_->size_ != 0 && rhs->photo_->size_ != 0) { - return lhs->photo_->size_ < rhs->photo_->size_; - } - return lhs->width_ * lhs->height_ < rhs->width_ * rhs->height_; - }); - + sort_photo_sizes(photos); return make_tl_object(photo->id, photo->has_stickers, std::move(photos)); } diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index def1318e..f91911fd 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -85,6 +85,7 @@ PhotoSize get_photo_size(FileManager *file_manager, FileType file_type, int64 id PhotoSize get_web_document_photo_size(FileManager *file_manager, FileType file_type, DialogId owner_dialog_id, tl_object_ptr web_document_ptr); tl_object_ptr get_photo_size_object(FileManager *file_manager, const PhotoSize *photo_size); +void sort_photo_sizes(vector> &sizes); bool operator==(const PhotoSize &lhs, const PhotoSize &rhs); bool operator!=(const PhotoSize &lhs, const PhotoSize &rhs); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 10a32181..aa362a90 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -43,6 +43,7 @@ #include "td/telegram/MessagesManager.h" #include "td/telegram/misc.h" #include "td/telegram/PasswordManager.h" +#include "td/telegram/Photo.h" #include "td/telegram/PrivacyManager.h" #include "td/telegram/SecretChatId.h" #include "td/telegram/SecretChatsManager.h" @@ -177,6 +178,7 @@ class GetWallpapersQuery : public Td::ResultHandler { get_photo_size(td->file_manager_.get(), FileType::Wallpaper, 0, 0, DialogId(), std::move(size_ptr)); sizes.push_back(get_photo_size_object(td->file_manager_.get(), &photo_size)); } + sort_photo_sizes(sizes); results->wallpapers_.push_back( make_tl_object(wallpaper->id_, std::move(sizes), wallpaper->color_)); break;