From 9b089bc19477f9e92cf8b2fb4282e059fd37a20f Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 7 Apr 2023 00:53:13 +0300 Subject: [PATCH] Improve on_set_profile_photo. --- td/telegram/ContactsManager.cpp | 32 +++++++++++++++++++++----------- td/telegram/ContactsManager.h | 2 +- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 28f113af1..225139033 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -571,15 +571,16 @@ class UploadProfilePhotoQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - if (!only_suggest_) { - td_->contacts_manager_->on_set_profile_photo(user_id_, result_ptr.move_as_ok(), is_fallback_, 0); - } - if (file_id_.is_valid()) { td_->file_manager_->delete_partial_remote_location(file_id_); } - promise_.set_value(Unit()); + if (!only_suggest_) { + td_->contacts_manager_->on_set_profile_photo(user_id_, result_ptr.move_as_ok(), is_fallback_, 0, + std::move(promise_)); + } else { + promise_.set_value(Unit()); + } } void on_error(Status status) final { @@ -637,9 +638,8 @@ class UpdateProfilePhotoQuery final : public Td::ResultHandler { return on_error(result_ptr.move_as_error()); } - td_->contacts_manager_->on_set_profile_photo(user_id_, result_ptr.move_as_ok(), is_fallback_, old_photo_id_); - - promise_.set_value(Unit()); + td_->contacts_manager_->on_set_profile_photo(user_id_, result_ptr.move_as_ok(), is_fallback_, old_photo_id_, + std::move(promise_)); } void on_error(Status status) final { @@ -696,8 +696,7 @@ class DeleteContactProfilePhotoQuery final : public Td::ResultHandler { auto ptr = result_ptr.move_as_ok(); ptr->photo_ = nullptr; - td_->contacts_manager_->on_set_profile_photo(user_id_, std::move(ptr), false, 0); - promise_.set_value(Unit()); + td_->contacts_manager_->on_set_profile_photo(user_id_, std::move(ptr), false, 0, std::move(promise_)); } void on_error(Status status) final { @@ -13531,7 +13530,7 @@ void ContactsManager::on_ignored_restriction_reasons_changed() { } void ContactsManager::on_set_profile_photo(UserId user_id, tl_object_ptr &&photo, - bool is_fallback, int64 old_photo_id) { + bool is_fallback, int64 old_photo_id, Promise &&promise) { LOG(INFO) << "Changed profile photo to " << to_string(photo); bool is_bot = is_user_bot(user_id); @@ -13539,10 +13538,21 @@ void ContactsManager::on_set_profile_photo(UserId user_id, tl_object_ptrusers_) { + if (get_user_id(user) == user_id) { + have_user = true; + } + } on_get_users(std::move(photo->users_), "on_set_profile_photo"); if (!is_bot) { add_set_profile_photo_to_cache(user_id, get_photo(td_, std::move(photo->photo_), DialogId(user_id)), is_fallback); } + if (have_user) { + promise.set_value(Unit()); + } else { + reload_user(user_id, std::move(promise)); + } } void ContactsManager::on_delete_profile_photo(int64 profile_photo_id, Promise promise) { diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 5996d7f35..dcf95fc2e 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -191,7 +191,7 @@ class ContactsManager final : public Actor { void on_update_user_need_phone_number_privacy_exception(UserId user_id, bool need_phone_number_privacy_exception); void on_set_profile_photo(UserId user_id, tl_object_ptr &&photo, bool is_fallback, - int64 old_photo_id); + int64 old_photo_id, Promise &&promise); void on_delete_profile_photo(int64 profile_photo_id, Promise promise);