diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 1ef10a96..926a8dc1 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7481,16 +7481,7 @@ void ContactsManager::update_user(User *u, UserId user_id, bool from_binlog, boo add_user_photo_id(u, user_id, u->photo.id, dialog_photo_get_file_ids(u->photo)); - UserFull *user_full = get_user_full(user_id); - if (user_full != nullptr) { - user_full->photos.clear(); - if (u->photo.id == 0) { - user_full->photo_count = 0; - } else { - user_full->photo_count = -1; - } - user_full->photos_offset = user_full->photo_count; - } + drop_user_photos(user_id, u->photo.id <= 0); } if (u->is_status_changed && user_id != get_my_id()) { auto left_time = get_user_was_online(u, user_id) - G()->server_time_cached(); @@ -7893,9 +7884,7 @@ void ContactsManager::on_get_user_full(tl_object_ptr &&u Photo photo = get_photo(td_->file_manager_.get(), std::move(user_full->profile_photo_), DialogId()); if (photo.id == -2) { - user->photo_count = 0; - user->photos_offset = 0; - user->photos.clear(); + drop_user_photos(user_id, true); } if ((user_full->flags_ & USER_FULL_FLAG_HAS_BOT_INFO) != 0 && !u->is_deleted) { on_update_user_full_bot_info(user, user_id, u->bot_info_version, std::move(user_full->bot_info_)); @@ -8340,16 +8329,7 @@ void ContactsManager::on_update_user_photo(User *u, UserId user_id, bool is_empty = photo == nullptr || photo->get_id() == telegram_api::userProfilePhotoEmpty::ID; pending_user_photos_[user_id] = std::move(photo); - UserFull *user_full = get_user_full(user_id); - if (user_full != nullptr) { - user_full->photos.clear(); - if (is_empty) { - user_full->photo_count = 0; - } else { - user_full->photo_count = -1; - } - user_full->photos_offset = user_full->photo_count; - } + drop_user_photos(user_id, is_empty); return; } @@ -8618,13 +8598,7 @@ void ContactsManager::on_update_user_full_need_phone_number_privacy_exception( void ContactsManager::on_delete_profile_photo(int64 profile_photo_id, Promise promise) { UserId my_id = get_my_id(); - UserFull *user_full = get_user_full(my_id); - if (user_full != nullptr) { - // drop photo cache - user_full->photos.clear(); - user_full->photo_count = -1; - user_full->photos_offset = -1; - } + drop_user_photos(my_id, false); if (G()->close_flag()) { return promise.set_value(Unit()); @@ -8633,6 +8607,19 @@ void ContactsManager::on_delete_profile_photo(int64 profile_photo_id, Promisephotos.clear(); + if (is_empty) { + user_full->photo_count = 0; + } else { + user_full->photo_count = -1; + } + user_full->photos_offset = user_full->photo_count; + } +} + void ContactsManager::drop_user_full(UserId user_id) { auto user_full = get_user_full_force(user_id); if (user_full == nullptr) { @@ -8641,9 +8628,7 @@ void ContactsManager::drop_user_full(UserId user_id) { user_full->expires_at = 0.0; - user_full->photos.clear(); - user_full->photo_count = -1; - user_full->photos_offset = -1; + drop_user_photos(user_id, false); user_full->is_inited = true; user_full->is_blocked = false; user_full->can_be_called = false; diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index e660b6e6..4c3064fe 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -1013,6 +1013,7 @@ class ContactsManager : public Actor { bool need_phone_number_privacy_exception); bool on_update_user_full_bot_info(UserFull *user_full, UserId user_id, int32 bot_info_version, tl_object_ptr &&bot_info); + void drop_user_photos(UserId user_id, bool is_empty); void drop_user_full(UserId user_id); void on_set_user_is_blocked_failed(UserId user_id, bool is_blocked, Status error);