From 6c5c26db7fffc7200454c23ade9f7cc710d3f58c Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 10 May 2023 01:50:06 +0300 Subject: [PATCH] Immediately ignore user photo if it's identifier is still the same. --- td/telegram/ContactsManager.cpp | 46 +++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index d4f6be907..93650b6c8 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -13145,29 +13145,37 @@ void ContactsManager::on_update_user_phone_number(User *u, UserId user_id, strin void ContactsManager::on_update_user_photo(User *u, UserId user_id, tl_object_ptr &&photo, const char *source) { - if (td_->auth_manager_->is_bot() && !G()->use_chat_info_database() && !u->is_photo_inited) { - if (photo != nullptr && photo->get_id() == telegram_api::userProfilePhoto::ID) { - auto *profile_photo = static_cast(photo.get()); - if ((profile_photo->flags_ & telegram_api::userProfilePhoto::STRIPPED_THUMB_MASK) != 0) { - profile_photo->flags_ -= telegram_api::userProfilePhoto::STRIPPED_THUMB_MASK; - profile_photo->stripped_thumb_ = BufferSlice(); + if (td_->auth_manager_->is_bot() && !G()->use_chat_info_database()) { + if (!u->is_photo_inited) { + if (photo != nullptr && photo->get_id() == telegram_api::userProfilePhoto::ID) { + auto *profile_photo = static_cast(photo.get()); + if ((profile_photo->flags_ & telegram_api::userProfilePhoto::STRIPPED_THUMB_MASK) != 0) { + profile_photo->flags_ -= telegram_api::userProfilePhoto::STRIPPED_THUMB_MASK; + profile_photo->stripped_thumb_ = BufferSlice(); + } + } + auto &old_photo = pending_user_photos_[user_id]; + if (!LOG_IS_STRIPPED(ERROR) && to_string(old_photo) == to_string(photo)) { + return; + } + + auto new_photo_id = get_profile_photo_id(photo); + old_photo = std::move(photo); + + drop_user_photos(user_id, new_photo_id == 0, "on_update_user_photo"); + auto user_full = get_user_full(user_id); // must not load UserFull + if (user_full != nullptr && new_photo_id != get_user_full_profile_photo_id(user_full)) { + // we didn't sent updateUser yet, so we must not sent updateUserFull with new_photo_id yet + drop_user_full_photos(user_full, user_id, 0, "on_update_user_photo"); } - } - auto &old_photo = pending_user_photos_[user_id]; - if (!LOG_IS_STRIPPED(ERROR) && to_string(old_photo) == to_string(photo)) { return; } - - auto new_photo_id = get_profile_photo_id(photo); - old_photo = std::move(photo); - - drop_user_photos(user_id, new_photo_id == 0, "on_update_user_photo"); - auto user_full = get_user_full(user_id); // must not load UserFull - if (user_full != nullptr && new_photo_id != get_user_full_profile_photo_id(user_full)) { - // we didn't sent updateUser yet, so we must not sent updateUserFull with new_photo_id yet - drop_user_full_photos(user_full, user_id, 0, "on_update_user_photo"); + if (u->is_received) { + auto new_photo_id = get_profile_photo_id(photo); + if (new_photo_id == u->photo.id) { + return; + } } - return; } do_update_user_photo(u, user_id, std::move(photo), source);