Ensure that full photo and is null if unknown.

This commit is contained in:
levlam 2022-11-05 01:19:56 +03:00
parent bbc3f5dace
commit ce2791fae3
2 changed files with 41 additions and 31 deletions

View File

@ -531,7 +531,7 @@ user id:int53 first_name:string last_name:string usernames:usernames phone_numbe
botInfo share_text:string description:string photo:photo animation:animation menu_button:botMenuButton commands:vector<botCommand> default_group_administrator_rights:chatAdministratorRights default_channel_administrator_rights:chatAdministratorRights = BotInfo;
//@description Contains full information about a user
//@photo User profile photo; may be null if empty or unknown
//@photo User profile photo; may be null if empty or unknown. If non-null, then it is the same photo as in user.profile_photo and chat.photo
//@is_blocked True, if the user is blocked by the current user
//@can_be_called True, if the user can be called
//@supports_video_calls True, if a video call can be created with the user
@ -714,7 +714,7 @@ chatJoinRequestsInfo total_count:int32 user_ids:vector<int53> = ChatJoinRequests
basicGroup id:int53 member_count:int32 status:ChatMemberStatus is_active:Bool upgraded_to_supergroup_id:int53 = BasicGroup;
//@description Contains full information about a basic group
//@photo Chat photo; may be null if empty or unknown
//@photo Chat photo; may be null if empty or unknown. If non-null, then it is the same photo as in chat.photo
//@param_description Group description. Updated only after the basic group is opened
//@creator_user_id User identifier of the creator of the group; 0 if unknown
//@members Group members
@ -745,7 +745,7 @@ basicGroupFullInfo photo:chatPhoto description:string creator_user_id:int53 memb
supergroup id:int53 usernames:usernames date:int32 status:ChatMemberStatus member_count:int32 has_linked_chat:Bool has_location:Bool sign_messages:Bool join_to_send_messages:Bool join_by_request:Bool is_slow_mode_enabled:Bool is_channel:Bool is_broadcast_group:Bool is_forum:Bool is_verified:Bool restriction_reason:string is_scam:Bool is_fake:Bool = Supergroup;
//@description Contains full information about a supergroup or channel
//@photo Chat photo; may be null if empty or unknown
//@photo Chat photo; may be null if empty or unknown. If non-null, then it is the same photo as in chat.photo
//@param_description Supergroup or channel description
//@member_count Number of members in the supergroup or channel; 0 if unknown
//@administrator_count Number of privileged users in the supergroup or channel; 0 if unknown

View File

@ -12240,7 +12240,8 @@ void ContactsManager::do_update_user_photo(User *u, UserId user_id, ProfilePhoto
<< "Update profile photo of " << user_id << " without access hash from " << source;
u->photo = new_photo;
u->is_photo_changed = true;
LOG(DEBUG) << "Photo has changed for " << user_id;
LOG(DEBUG) << "Photo has changed for " << user_id << " to " << u->photo
<< ", invalidate_photo_cache = " << invalidate_photo_cache;
u->is_changed = true;
if (invalidate_photo_cache) {
@ -12634,6 +12635,8 @@ void ContactsManager::add_profile_photo_to_cache(UserId user_id, Photo &&photo)
return;
}
LOG(INFO) << "Add prifile photo " << photo.id.get() << " to cache";
// update photo list
auto it = user_photos_.find(user_id);
if (it != user_photos_.end() && it->second.count != -1) {
@ -12650,6 +12653,11 @@ void ContactsManager::add_profile_photo_to_cache(UserId user_id, Photo &&photo)
}
}
// update ProfilePhoto in User
do_update_user_photo(u, user_id, as_profile_photo(td_->file_manager_.get(), user_id, u->access_hash, photo), false,
"add_profile_photo_to_cache");
update_user(u, user_id);
// update Photo in UserFull
auto user_full = get_user_full_force(user_id);
if (user_full != nullptr) {
@ -12660,11 +12668,6 @@ void ContactsManager::add_profile_photo_to_cache(UserId user_id, Photo &&photo)
}
update_user_full(user_full, user_id, "add_profile_photo_to_cache");
}
// update ProfilePhoto in User
do_update_user_photo(u, user_id, as_profile_photo(td_->file_manager_.get(), user_id, u->access_hash, photo), false,
"add_profile_photo_to_cache");
update_user(u, user_id);
}
bool ContactsManager::delete_profile_photo_from_cache(UserId user_id, int64 profile_photo_id, bool send_updates) {
@ -12673,6 +12676,9 @@ bool ContactsManager::delete_profile_photo_from_cache(UserId user_id, int64 prof
// we have subsequence of user photos in user_photos_
// ProfilePhoto in User and Photo in UserFull
LOG(INFO) << "Delete prifile photo " << profile_photo_id << " from cache with" << (send_updates ? "" : "out")
<< " updates";
User *u = get_user_force(user_id);
bool is_main_photo_deleted = u != nullptr && u->photo.id == profile_photo_id;
@ -12698,35 +12704,19 @@ bool ContactsManager::delete_profile_photo_from_cache(UserId user_id, int64 prof
user_photos->offset = -1;
}
}
bool have_new_photo =
it != user_photos_.end() && it->second.count != -1 && it->second.offset == 0 && !it->second.photos.empty();
// update Photo in UserFull
auto user_full = get_user_full_force(user_id);
if (user_full != nullptr && !user_full->photo.is_empty() &&
(is_main_photo_deleted || user_full->photo.id.get() == profile_photo_id)) {
if (it != user_photos_.end() && it->second.count != -1 && it->second.offset == 0 && !it->second.photos.empty()) {
// found exact new photo
if (it->second.photos[0] != user_full->photo) {
user_full->photo = it->second.photos[0];
user_full->is_changed = true;
}
} else {
// repair UserFull photo
user_full->expires_at = 0.0;
user_full->photo = Photo();
user_full->is_changed = true;
load_user_full(user_id, true, Auto(), "delete_profile_photo_from_cache");
}
if (send_updates) {
update_user_full(user_full, user_id, "delete_profile_photo_from_cache");
}
if (user_full != nullptr && user_full->photo.id.get() == profile_photo_id) {
// user_full->photo is empty or coincides with u->photo
CHECK(is_main_photo_deleted);
}
// update ProfilePhoto in User
bool need_reget_user = false;
if (is_main_photo_deleted) {
if (it != user_photos_.end() && it->second.count != -1 && it->second.offset == 0 && !it->second.photos.empty()) {
// found exact new photo
if (have_new_photo) {
do_update_user_photo(u, user_id,
as_profile_photo(td_->file_manager_.get(), user_id, u->access_hash, it->second.photos[0]),
false, "delete_profile_photo_from_cache");
@ -12737,6 +12727,26 @@ bool ContactsManager::delete_profile_photo_from_cache(UserId user_id, int64 prof
if (send_updates) {
update_user(u, user_id);
}
// update Photo in UserFull
if (user_full != nullptr) {
if (have_new_photo) {
if (it->second.photos[0] != user_full->photo) {
user_full->photo = it->second.photos[0];
user_full->is_changed = true;
}
} else {
// repair UserFull photo
user_full->expires_at = 0.0;
user_full->photo = Photo();
user_full->is_changed = true;
load_user_full(user_id, true, Auto(), "delete_profile_photo_from_cache");
}
if (send_updates) {
update_user_full(user_full, user_id, "delete_profile_photo_from_cache");
}
}
}
return need_reget_user;