diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 926a8dc15..75c1efedd 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -7934,21 +7934,22 @@ void ContactsManager::on_get_user_photos(UserId user_id, int32 offset, int32 lim return; } - UserFull *user = &users_full_[user_id]; - user->photo_count = total_count; - CHECK(user->getting_photos_now); - user->getting_photos_now = false; + UserPhotos *user_photos = &user_photos_[user_id]; + user_photos->photo_count = total_count; + CHECK(user_photos->getting_photos_now); + user_photos->getting_photos_now = false; - if (user->photos_offset == -1) { - user->photos_offset = 0; - CHECK(user->photos.empty()); + if (user_photos->photos_offset == -1) { + user_photos->photos_offset = 0; + CHECK(user_photos->photos.empty()); } - if (offset != narrow_cast(user->photos.size()) + user->photos_offset) { + if (offset != narrow_cast(user_photos->photos.size()) + user_photos->photos_offset) { LOG(INFO) << "Inappropriate offset to append " << user_id << " profile photos to cache: offset = " << offset - << ", current_offset = " << user->photos_offset << ", photo_count = " << user->photos.size(); - user->photos.clear(); - user->photos_offset = offset; + << ", current_offset = " << user_photos->photos_offset + << ", photo_count = " << user_photos->photos.size(); + user_photos->photos.clear(); + user_photos->photos_offset = offset; } for (auto &photo : photos) { @@ -7960,8 +7961,8 @@ void ContactsManager::on_get_user_photos(UserId user_id, int32 offset, int32 lim continue; } - user->photos.push_back(std::move(user_photo)); - add_user_photo_id(u, user_id, user->photos.back().id, photo_get_file_ids(user->photos.back())); + user_photos->photos.push_back(std::move(user_photo)); + add_user_photo_id(u, user_id, user_photos->photos.back().id, photo_get_file_ids(user_photos->photos.back())); } } @@ -8608,15 +8609,16 @@ void ContactsManager::on_delete_profile_photo(int64 profile_photo_id, Promisephotos.clear(); + auto it = user_photos_.find(user_id); + if (it != user_photos_.end()) { + auto user_photos = &it->second; + user_photos->photos.clear(); if (is_empty) { - user_full->photo_count = 0; + user_photos->photo_count = 0; } else { - user_full->photo_count = -1; + user_photos->photo_count = -1; } - user_full->photos_offset = user_full->photo_count; + user_photos->photos_offset = user_photos->photo_count; } } @@ -10470,32 +10472,32 @@ std::pair> ContactsManager::get_user_profile_photos return result; } - auto user_full = &users_full_[user_id]; - if (user_full->getting_photos_now) { + auto user_photos = &user_photos_[user_id]; + if (user_photos->getting_photos_now) { promise.set_error(Status::Error(400, "Request for new profile photos has already been sent")); return result; } - if (user_full->photo_count != -1) { // know photo count - CHECK(user_full->photos_offset != -1); - result.first = user_full->photo_count; + if (user_photos->photo_count != -1) { // know photo count + CHECK(user_photos->photos_offset != -1); + result.first = user_photos->photo_count; - if (offset >= user_full->photo_count) { + if (offset >= user_photos->photo_count) { // offset if too big promise.set_value(Unit()); return result; } - if (limit > user_full->photo_count - offset) { - limit = user_full->photo_count - offset; + if (limit > user_photos->photo_count - offset) { + limit = user_photos->photo_count - offset; } - int32 cache_begin = user_full->photos_offset; - int32 cache_end = cache_begin + narrow_cast(user_full->photos.size()); + int32 cache_begin = user_photos->photos_offset; + int32 cache_end = cache_begin + narrow_cast(user_photos->photos.size()); if (cache_begin <= offset && offset + limit <= cache_end) { // answer query from cache for (int i = 0; i < limit; i++) { - result.second.push_back(&user_full->photos[i + offset - cache_begin]); + result.second.push_back(&user_photos->photos[i + offset - cache_begin]); } promise.set_value(Unit()); return result; @@ -10508,7 +10510,7 @@ std::pair> ContactsManager::get_user_profile_photos } } - user_full->getting_photos_now = true; + user_photos->getting_photos_now = true; if (limit < MAX_GET_PROFILE_PHOTOS / 5) { limit = MAX_GET_PROFILE_PHOTOS / 5; // make limit reasonable diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 4c3064fed..c900952a6 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -585,21 +585,22 @@ class ContactsManager : public Actor { void parse(ParserT &parser); }; - // do not forget to update drop_user_full and on_get_user_full - struct UserFull { + struct UserPhotos { vector photos; int32 photo_count = -1; int32 photos_offset = -1; + bool getting_photos_now = false; + }; + // do not forget to update drop_user_full and on_get_user_full + struct UserFull { unique_ptr bot_info; string about; int32 common_chat_count = 0; - bool getting_photos_now = false; - - bool is_inited = false; // photos and bot_info may be inited regardless this flag + bool is_inited = false; // bot_info may be inited regardless of this flag bool is_blocked = false; bool can_be_called = false; bool has_private_calls = false; @@ -1254,6 +1255,7 @@ class ContactsManager : public Actor { std::unordered_map users_; std::unordered_map users_full_; + std::unordered_map user_photos_; mutable std::unordered_set unknown_users_; std::unordered_map, UserIdHash> pending_user_photos_; struct UserIdPhotoIdHash {