From 3f55703211de5ad8f0017746f576905496dae77d Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 23 Dec 2022 13:19:56 +0300 Subject: [PATCH] Register suggested profile photos. --- td/telegram/ContactsManager.cpp | 17 +++++++++++++++++ td/telegram/ContactsManager.h | 2 ++ td/telegram/MessageContent.cpp | 3 +++ 3 files changed, 22 insertions(+) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index b73e78a41..2bf0cc49d 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -12698,6 +12698,23 @@ void ContactsManager::do_update_user_photo(User *u, UserId user_id, ProfilePhoto } } +void ContactsManager::register_suggested_profile_photo(const Photo &photo) { + auto photo_file_ids = photo_get_file_ids(photo); + if (photo.is_empty() || photo_file_ids.empty()) { + return; + } + auto first_file_id = photo_file_ids[0]; + auto file_type = td_->file_manager_->get_file_view(first_file_id).get_type(); + if (file_type == FileType::ProfilePhoto) { + return; + } + CHECK(file_type == FileType::Photo); + auto photo_id = photo.id.get(); + if (photo_id != 0) { + my_photo_file_id_[photo_id] = first_file_id; + } +} + void ContactsManager::register_user_photo(User *u, UserId user_id, const Photo &photo) { auto photo_file_ids = photo_get_file_ids(photo); if (photo.is_empty() || photo_file_ids.empty()) { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 4d0844f12..0f26cb0d8 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -361,6 +361,8 @@ class ContactsManager final : public Actor { void get_is_location_visible(Promise &&promise); + void register_suggested_profile_photo(const Photo &photo); + FileId get_profile_photo_file_id(int64 photo_id) const; void set_profile_photo(const td_api::object_ptr &input_photo, bool is_fallback, diff --git a/td/telegram/MessageContent.cpp b/td/telegram/MessageContent.cpp index 08a678cb1..ef5467770 100644 --- a/td/telegram/MessageContent.cpp +++ b/td/telegram/MessageContent.cpp @@ -4050,6 +4050,9 @@ void register_message_content(Td *td, const MessageContent *content, FullMessage case MessageContentType::GiftPremium: return td->stickers_manager_->register_premium_gift(static_cast(content)->months, full_message_id, source); + case MessageContentType::SuggestProfilePhoto: + return td->contacts_manager_->register_suggested_profile_photo( + static_cast(content)->photo); default: return; }