From a80794ffebf62b74c0b6bc25cfd85f6bb20ef5b2 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 22 Dec 2022 22:38:30 +0300 Subject: [PATCH] Explicitly call drop_user_full_photos. --- td/telegram/ContactsManager.cpp | 44 ++++++--------------------------- td/telegram/ContactsManager.h | 2 +- td/telegram/Photo.cpp | 7 ++++++ td/telegram/Photo.h | 2 ++ 4 files changed, 18 insertions(+), 37 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 487a21c8a..6c75ed12e 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -11972,7 +11972,7 @@ void ContactsManager::on_get_user_full(tl_object_ptr &&u register_user_photo(u, user_id, user_full->fallback_photo); } if (photo_ptr->is_empty()) { - drop_user_photos(user_id, true, false, "on_get_user_full"); + drop_user_photos(user_id, true, "on_get_user_full"); } // User must be updated before UserFull @@ -12650,10 +12650,11 @@ void ContactsManager::on_update_user_photo(User *u, UserId user_id, return; } - bool is_empty = photo == nullptr || photo->get_id() == telegram_api::userProfilePhotoEmpty::ID; + auto new_photo_id = get_profile_photo_id(photo); old_photo = std::move(photo); - drop_user_photos(user_id, is_empty, true, "on_update_user_photo"); + drop_user_photos(user_id, new_photo_id == 0, "on_update_user_photo"); + drop_user_full_photos(get_user_full(user_id), user_id, new_photo_id); // must not load UserFull return; } @@ -12682,10 +12683,9 @@ void ContactsManager::do_update_user_photo(User *u, UserId user_id, ProfilePhoto u->is_changed = true; if (invalidate_photo_cache) { - drop_user_photos(user_id, !u->photo.small_file_id.is_valid(), true, source); - } else { - drop_user_full_photos(get_user_full(user_id), user_id, u->photo.id); // must not load UserFull + drop_user_photos(user_id, u->photo.id == 0, source); } + drop_user_full_photos(get_user_full(user_id), user_id, u->photo.id); // must not load UserFull } else if (need_update_dialog_photo_minithumbnail(u->photo.minithumbnail, new_photo.minithumbnail)) { LOG(DEBUG) << "Photo minithumbnail has changed for " << user_id << " from " << source; u->photo.minithumbnail = std::move(new_photo.minithumbnail); @@ -13247,7 +13247,7 @@ void ContactsManager::drop_user_full_photos(UserFull *user_full, UserId user_id, } } -void ContactsManager::drop_user_photos(UserId user_id, bool is_empty, bool drop_user_full_photo, const char *source) { +void ContactsManager::drop_user_photos(UserId user_id, bool is_empty, const char *source) { LOG(INFO) << "Drop user photos to " << (is_empty ? "empty" : "unknown") << " from " << source; auto user_photos = user_photos_.get_pointer(user_id); if (user_photos != nullptr) { @@ -13262,40 +13262,12 @@ void ContactsManager::drop_user_photos(UserId user_id, bool is_empty, bool drop_ user_photos->offset = user_photos->count; } } - - if (drop_user_full_photo) { - auto user_full = get_user_full(user_id); // must not load UserFull - if (user_full != nullptr) { - if (!user_full->photo.is_empty()) { - user_full->photo = Photo(); - user_full->is_changed = true; - } - if (!user_full->personal_photo.is_empty()) { - user_full->personal_photo = Photo(); - user_full->is_changed = true; - } - if (!user_full->fallback_photo.is_empty()) { - user_full->fallback_photo = Photo(); - user_full->is_changed = true; - } - if (!is_empty) { - if (user_full->expires_at > 0.0) { - user_full->expires_at = 0.0; - user_full->need_save_to_database = true; - } - reload_user_full(user_id, Auto()); - } - if (user_full->is_update_user_full_sent) { - update_user_full(user_full, user_id, "drop_user_photos"); - } - } - } } void ContactsManager::drop_user_full(UserId user_id) { auto user_full = get_user_full_force(user_id); - drop_user_photos(user_id, false, false, "drop_user_full"); + drop_user_photos(user_id, false, "drop_user_full"); if (user_full == nullptr) { return; diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 16d92d489..4d0844f12 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1375,7 +1375,7 @@ class ContactsManager final : public Actor { void add_set_profile_photo_to_cache(UserId user_id, Photo &&photo, bool is_fallback); bool delete_profile_photo_from_cache(UserId user_id, int64 profile_photo_id, bool send_updates); void drop_user_full_photos(UserFull *user_full, UserId user_id, int64 expected_photo_id); - void drop_user_photos(UserId user_id, bool is_empty, bool drop_user_full_photo, const char *source); + void drop_user_photos(UserId user_id, bool is_empty, const char *source); void drop_user_full(UserId user_id); void on_update_chat_status(Chat *c, ChatId chat_id, DialogParticipantStatus status); diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index feacf6cdf..545c72555 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -25,6 +25,13 @@ namespace td { +int64 get_profile_photo_id(const tl_object_ptr &profile_photo_ptr) { + if (profile_photo_ptr != nullptr && profile_photo_ptr->get_id() == telegram_api::userProfilePhoto::ID) { + return static_cast(profile_photo_ptr.get())->photo_id_; + } + return 0; +} + ProfilePhoto get_profile_photo(FileManager *file_manager, UserId user_id, int64 user_access_hash, tl_object_ptr &&profile_photo_ptr) { ProfilePhoto result; diff --git a/td/telegram/Photo.h b/td/telegram/Photo.h index c7604e323..7aa7d561d 100644 --- a/td/telegram/Photo.h +++ b/td/telegram/Photo.h @@ -65,6 +65,8 @@ struct Photo { } }; +int64 get_profile_photo_id(const tl_object_ptr &profile_photo_ptr); + ProfilePhoto get_profile_photo(FileManager *file_manager, UserId user_id, int64 user_access_hash, tl_object_ptr &&profile_photo_ptr); tl_object_ptr get_profile_photo_object(FileManager *file_manager,