Sort wallpapers by size.

GitOrigin-RevId: 497dc15ea3f6b8c5cd0bc0f2e6ce65a338d19b90
This commit is contained in:
levlam 2018-03-09 16:56:42 +03:00
parent 9633b50112
commit 88ad4a370c
3 changed files with 13 additions and 7 deletions

View File

@ -390,6 +390,15 @@ tl_object_ptr<td_api::photoSize> 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<td_api::object_ptr<td_api::photoSize>> &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<td_api::photo> 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<td_api::photo>(photo->id, photo->has_stickers, std::move(photos));
}

View File

@ -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<telegram_api::WebDocument> web_document_ptr);
tl_object_ptr<td_api::photoSize> get_photo_size_object(FileManager *file_manager, const PhotoSize *photo_size);
void sort_photo_sizes(vector<td_api::object_ptr<td_api::photoSize>> &sizes);
bool operator==(const PhotoSize &lhs, const PhotoSize &rhs);
bool operator!=(const PhotoSize &lhs, const PhotoSize &rhs);

View File

@ -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<td_api::wallpaper>(wallpaper->id_, std::move(sizes), wallpaper->color_));
break;