diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index e9792efe8..74b9df9e8 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -344,6 +344,13 @@ botInfo description:string commands:vector = BotInfo; chatLocation location:location address:string = ChatLocation; +//@description Contains full information about a user profile photo @id Unique user profile photo identifier @added_date Point in time (Unix timestamp) when the photo has been added @sizes Available variants of the user photo, in different sizes +userProfilePhoto id:int64 added_date:int32 sizes:vector = UserProfilePhoto; + +//@description Contains part of the list of user photos @total_count Total number of user profile photos @photos A list of photos +userProfilePhotos total_count:int32 photos:vector = UserProfilePhotos; + + //@description Represents a user @id User identifier @first_name First name of the user @last_name Last name of the user @username Username of the user //@phone_number Phone number of the user @status Current online status of the user @profile_photo Profile photo of the user; may be null //@is_contact The user is a contact of the current user @@ -354,17 +361,13 @@ chatLocation location:location address:string = ChatLocation; //@have_access If false, the user is inaccessible, and the only information known about the user is inside this class. It can't be passed to any method except GetUser @type Type of the user @language_code IETF language tag of the user's language; only available to bots user id:int32 first_name:string last_name:string username:string phone_number:string status:UserStatus profile_photo:profilePhoto is_contact:Bool is_mutual_contact:Bool is_verified:Bool is_support:Bool restriction_reason:string is_scam:Bool have_access:Bool type:UserType language_code:string = User; -//@description Contains full information about a user (except the full list of profile photos) @is_blocked True, if the user is blacklisted by the current user +//@description Contains full information about a user +//@photo User profile photo; may be null +//@is_blocked True, if the user is blocked by the current user //@can_be_called True, if the user can be called @has_private_calls True, if the user can't be called due to their privacy settings //@need_phone_number_privacy_exception True, if the current user needs to explicitly allow to share their phone number with the user when the method addContact is used //@bio A short user bio @share_text For bots, the text that is included with the link when users share the bot @group_in_common_count Number of group chats where both the other user and the current user are a member; 0 for the current user @bot_info If the user is a bot, information about the bot; may be null -userFullInfo is_blocked:Bool can_be_called:Bool has_private_calls:Bool need_phone_number_privacy_exception:Bool bio:string share_text:string group_in_common_count:int32 bot_info:botInfo = UserFullInfo; - -//@description Contains full information about a user profile photo @id Unique user profile photo identifier @added_date Point in time (Unix timestamp) when the photo has been added @sizes Available variants of the user photo, in different sizes -userProfilePhoto id:int64 added_date:int32 sizes:vector = UserProfilePhoto; - -//@description Contains part of the list of user photos @total_count Total number of user profile photos @photos A list of photos -userProfilePhotos total_count:int32 photos:vector = UserProfilePhotos; +userFullInfo photo:userProfilePhoto is_blocked:Bool can_be_called:Bool has_private_calls:Bool need_phone_number_privacy_exception:Bool bio:string share_text:string group_in_common_count:int32 bot_info:botInfo = UserFullInfo; //@description Represents a list of users @total_count Approximate total count of users found @user_ids A list of user identifiers users total_count:int32 user_ids:vector = Users; @@ -3956,10 +3959,10 @@ sendCallDebugInformation call_id:int32 debug_information:string = Ok; -//@description Adds a user to the blacklist @user_id User identifier +//@description Blocks a user @user_id User identifier blockUser user_id:int32 = Ok; -//@description Removes a user from the blacklist @user_id User identifier +//@description Unblocks a user @user_id User identifier unblockUser user_id:int32 = Ok; //@description Returns users that were blocked by the current user @offset Number of users to skip in the result; must be non-negative @limit The maximum number of users to return; up to 100 diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 653084d59..c57650f59 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 0013acbac..a2ac95e42 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -8455,7 +8455,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)); - drop_user_photos(user_id, u->photo.id <= 0, "update_user"); + drop_user_photos(user_id, u->photo.id <= 0, true, "update_user"); } if (u->is_status_changed && user_id != get_my_id()) { auto left_time = get_user_was_online(u, user_id) - G()->server_time_cached(); @@ -8850,7 +8850,7 @@ void ContactsManager::on_get_user_full(tl_object_ptr &&u } on_get_user(std::move(user_full->user_), "on_get_user_full"); - const User *u = get_user(user_id); + User *u = get_user(user_id); if (u == nullptr) { return; } @@ -8900,10 +8900,13 @@ void ContactsManager::on_get_user_full(tl_object_ptr &&u user->is_changed = true; } - Photo photo = get_photo(td_->file_manager_.get(), std::move(user_full->profile_photo_), DialogId()); - if (photo.id == -2) { - drop_user_photos(user_id, true, "on_get_user_full"); + user->photo = get_photo(td_->file_manager_.get(), std::move(user_full->profile_photo_), DialogId()); + if (user->photo.id == -2) { + drop_user_photos(user_id, true, false, "on_get_user_full"); + } else { + add_user_photo_id(u, user_id, user->photo.id, photo_get_file_ids(user->photo)); } + if (user_full->bot_info_ != nullptr) { if (on_update_bot_info(std::move(user_full->bot_info_), false)) { user->need_send_update = true; @@ -9417,7 +9420,7 @@ void ContactsManager::on_update_user_photo(User *u, UserId user_id, bool is_empty = photo == nullptr || photo->get_id() == telegram_api::userProfilePhotoEmpty::ID; old_photo = std::move(photo); - drop_user_photos(user_id, is_empty, "on_update_user_photo"); + drop_user_photos(user_id, is_empty, true, "on_update_user_photo"); return; } @@ -9704,7 +9707,7 @@ void ContactsManager::on_ignored_restriction_reasons_changed() { void ContactsManager::on_delete_profile_photo(int64 profile_photo_id, Promise promise) { UserId my_id = get_my_id(); - drop_user_photos(my_id, false, "on_delete_profile_photo"); + drop_user_photos(my_id, false, true, "on_delete_profile_photo"); if (G()->close_flag()) { return promise.set_value(Unit()); @@ -9713,7 +9716,7 @@ void ContactsManager::on_delete_profile_photo(int64 profile_photo_id, Promisesecond; @@ -9729,10 +9732,33 @@ void ContactsManager::drop_user_photos(UserId user_id, bool is_empty, const char user_photos->count = new_count; user_photos->offset = user_photos->count; } + + if (drop_user_full_photo) { + auto user_full = get_user_full_force(user_id); + if (user_full == nullptr) { + return; + } + + if (is_empty) { + if (user_full->photo.id != -2) { + user_full->photo = Photo(); + user_full->photo.id = -2; + user_full->is_changed = true; + } + } else { + if (user_full->expires_at > 0.0) { + user_full->expires_at = 0.0; + user_full->need_save_to_database = true; + + get_user_full(user_id, true, Auto()); + } + } + update_user_full(user_full, user_id); + } } void ContactsManager::drop_user_full(UserId user_id) { - drop_user_photos(user_id, false, "drop_user_full"); + drop_user_photos(user_id, false, false, "drop_user_full"); bot_infos_.erase(user_id); if (G()->parameters().use_chat_info_db) { @@ -9746,6 +9772,8 @@ void ContactsManager::drop_user_full(UserId user_id) { user_full->expires_at = 0.0; + user_full->photo = Photo(); + user_full->photo.id = -2; user_full->is_blocked = false; user_full->can_be_called = false; user_full->has_private_calls = false; @@ -13439,9 +13467,9 @@ tl_object_ptr ContactsManager::get_user_full_info_object(U CHECK(user_full != nullptr); bool is_bot = is_user_bot(user_id); return make_tl_object( - user_full->is_blocked, user_full->can_be_called, user_full->has_private_calls, - user_full->need_phone_number_privacy_exception, is_bot ? string() : user_full->about, - is_bot ? user_full->about : string(), user_full->common_chat_count, + get_user_profile_photo_object(td_->file_manager_.get(), &user_full->photo), user_full->is_blocked, + user_full->can_be_called, user_full->has_private_calls, user_full->need_phone_number_privacy_exception, + is_bot ? string() : user_full->about, is_bot ? user_full->about : string(), user_full->common_chat_count, is_bot ? get_bot_info_object(user_id) : nullptr); } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 30a192e5a..b087b147e 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -646,6 +646,8 @@ class ContactsManager : public Actor { // do not forget to update drop_user_full and on_get_user_full struct UserFull { + Photo photo; + string about; int32 common_chat_count = 0; @@ -1105,7 +1107,7 @@ class ContactsManager : public Actor { void on_update_user_full_common_chat_count(UserFull *user_full, UserId user_id, int32 common_chat_count); void on_update_user_full_need_phone_number_privacy_exception(UserFull *user_full, UserId user_id, bool need_phone_number_privacy_exception); - void drop_user_photos(UserId user_id, bool is_empty, const char *source); + void drop_user_photos(UserId user_id, bool is_empty, bool drop_user_full_photo, const char *source); void drop_user_full(UserId user_id); void on_set_user_is_blocked_failed(UserId user_id, bool is_blocked, Status error); diff --git a/td/telegram/Photo.cpp b/td/telegram/Photo.cpp index 84a7da60a..96b340ea7 100644 --- a/td/telegram/Photo.cpp +++ b/td/telegram/Photo.cpp @@ -603,6 +603,7 @@ Photo get_photo(FileManager *file_manager, tl_object_ptr && } Photo get_photo(FileManager *file_manager, tl_object_ptr &&photo, DialogId owner_dialog_id) { + CHECK(photo != nullptr); Photo res; res.id = photo->id_;