From 121dd73bfbaceb02674deb59d4f21c0303c88efb Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 15 Dec 2022 15:27:22 +0300 Subject: [PATCH] Add ContactsManager::get_user_full_profile_photo_id. --- td/telegram/ContactsManager.cpp | 15 ++++++++++----- td/telegram/ContactsManager.h | 1 + 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index f1d74d503..34a2498df 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -10741,8 +10741,7 @@ void ContactsManager::on_load_user_full_from_database(UserId user_id, string val User *u = get_user(user_id); CHECK(u != nullptr); - auto user_full_photo_id = - !user_full->personal_photo.is_empty() ? user_full->personal_photo.id.get() : user_full->photo.id.get(); + auto user_full_photo_id = get_user_full_profile_photo_id(user_full); if (u->photo.id != user_full_photo_id) { user_full->photo = Photo(); user_full->personal_photo = Photo(); @@ -12484,7 +12483,7 @@ void ContactsManager::do_update_user_photo(User *u, UserId user_id, ProfilePhoto } else { auto user_full = get_user_full(user_id); // must not load UserFull if (user_full != nullptr) { - auto user_full_photo_id = u->photo.is_personal ? user_full->personal_photo.id.get() : user_full->photo.id.get(); + auto user_full_photo_id = get_user_full_profile_photo_id(user_full); if (u->photo.id == 0 || u->photo.id != user_full_photo_id) { // if profile photo is unknown, we must drop both photos if (!user_full->photo.is_empty()) { @@ -12868,6 +12867,13 @@ void ContactsManager::on_delete_profile_photo(int64 profile_photo_id, Promisepersonal_photo.is_empty()) { + return user_full->personal_photo.id.get(); + } + return user_full->photo.id.get(); +} + void ContactsManager::add_set_profile_photo_to_cache(UserId user_id, Photo &&photo) { if (photo.is_empty()) { return; @@ -12967,8 +12973,7 @@ bool ContactsManager::delete_profile_photo_from_cache(UserId user_id, int64 prof // check that user_full photo is empty or coincides with u->photo if (user_full != nullptr && (!user_full->personal_photo.is_empty() || !user_full->photo.is_empty())) { - auto user_full_photo_id = - !user_full->personal_photo.is_empty() ? user_full->personal_photo.id.get() : user_full->photo.id.get(); + auto user_full_photo_id = get_user_full_profile_photo_id(user_full); if (user_full_photo_id == profile_photo_id) { CHECK(is_main_photo_deleted); } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 61b2a8a31..72b0e9f5d 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1361,6 +1361,7 @@ class ContactsManager final : public Actor { bool need_phone_number_privacy_exception) const; UserPhotos *add_user_photos(UserId user_id); + int64 get_user_full_profile_photo_id(const UserFull *user_full); void add_set_profile_photo_to_cache(UserId user_id, Photo &&photo); bool delete_profile_photo_from_cache(UserId user_id, int64 profile_photo_id, bool send_updates); void drop_user_photos(UserId user_id, bool is_empty, bool drop_user_full_photo, const char *source);