From b6f711044f96ac987f13e497541e8811bb0206d6 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 28 Apr 2022 20:33:24 +0300 Subject: [PATCH] Add as_dialog_photo. --- td/telegram/Photo.cpp | 19 ++++++++++++++----- td/telegram/Photo.h | 3 +++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 4d059e10c..eff37fcf5 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -160,9 +160,10 @@ DialogPhoto as_fake_dialog_photo(const Photo &photo, DialogId dialog_id) { return result; } -ProfilePhoto as_profile_photo(FileManager *file_manager, UserId user_id, int64 user_access_hash, const Photo &photo) { - ProfilePhoto result; - static_cast(result) = as_fake_dialog_photo(photo, DialogId(user_id)); +DialogPhoto as_dialog_photo(FileManager *file_manager, DialogId dialog_id, int64 dialog_access_hash, + const Photo &photo) { + DialogPhoto result; + static_cast(result) = as_fake_dialog_photo(photo, dialog_id); if (!result.small_file_id.is_valid()) { return result; } @@ -173,18 +174,26 @@ ProfilePhoto as_profile_photo(FileManager *file_manager, UserId user_id, int64 u auto remote = file_view.remote_location(); CHECK(remote.is_photo()); CHECK(!remote.is_web()); - remote.set_source(PhotoSizeSource::dialog_photo(DialogId(user_id), user_access_hash, is_big)); + remote.set_source(PhotoSizeSource::dialog_photo(dialog_id, dialog_access_hash, is_big)); return file_manager->register_remote(std::move(remote), FileLocationSource::FromServer, DialogId(), file_view.size(), file_view.expected_size(), file_view.remote_name()); }; - result.id = photo.id.get(); result.small_file_id = reregister_photo(false, result.small_file_id); result.big_file_id = reregister_photo(true, result.big_file_id); return result; } +ProfilePhoto as_profile_photo(FileManager *file_manager, UserId user_id, int64 user_access_hash, const Photo &photo) { + ProfilePhoto result; + static_cast(result) = as_dialog_photo(file_manager, DialogId(user_id), user_access_hash, photo); + if (result.small_file_id.is_valid()) { + result.id = photo.id.get(); + } + return result; +} + bool operator==(const DialogPhoto &lhs, const DialogPhoto &rhs) { return lhs.small_file_id == rhs.small_file_id && lhs.big_file_id == rhs.big_file_id && lhs.minithumbnail == rhs.minithumbnail && lhs.has_animation == rhs.has_animation; diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index 0b2953082..f54484f56 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -69,6 +69,9 @@ tl_object_ptr get_chat_photo_info_object(FileManager *fil DialogPhoto as_fake_dialog_photo(const Photo &photo, DialogId dialog_id); +DialogPhoto as_dialog_photo(FileManager *file_manager, DialogId dialog_id, int64 dialog_access_hash, + const Photo &photo); + ProfilePhoto as_profile_photo(FileManager *file_manager, UserId user_id, int64 user_access_hash, const Photo &photo); vector dialog_photo_get_file_ids(const DialogPhoto &dialog_photo);