From d6423f60be0230a0d04d473e3f16a5a35109ba43 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 17 Dec 2023 23:12:03 +0300 Subject: [PATCH] Remove separate UpdateProfileColorQuery. --- td/telegram/ContactsManager.cpp | 75 +++++++-------------------------- td/telegram/ContactsManager.h | 4 +- 2 files changed, 18 insertions(+), 61 deletions(-) diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 86de72533..f4c8bb6b2 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -775,6 +775,7 @@ class DeleteProfilePhotoQuery final : public Td::ResultHandler { class UpdateColorQuery final : public Td::ResultHandler { Promise promise_; + bool for_profile_; AccentColorId accent_color_id_; CustomEmojiId background_custom_emoji_id_; @@ -782,10 +783,14 @@ class UpdateColorQuery final : public Td::ResultHandler { explicit UpdateColorQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send(AccentColorId accent_color_id, CustomEmojiId background_custom_emoji_id) { + void send(bool for_profile, AccentColorId accent_color_id, CustomEmojiId background_custom_emoji_id) { + for_profile_ = for_profile; accent_color_id_ = accent_color_id; background_custom_emoji_id_ = background_custom_emoji_id; int32 flags = 0; + if (for_profile) { + flags |= telegram_api::account_updateColor::FOR_PROFILE_MASK; + } if (accent_color_id.is_valid()) { flags |= telegram_api::account_updateColor::COLOR_MASK; } @@ -805,48 +810,7 @@ class UpdateColorQuery final : public Td::ResultHandler { } LOG(DEBUG) << "Receive result for UpdateColorQuery: " << result_ptr.ok(); - td_->contacts_manager_->on_update_accent_color_success(accent_color_id_, background_custom_emoji_id_); - promise_.set_value(Unit()); - } - - void on_error(Status status) final { - promise_.set_error(std::move(status)); - } -}; - -class UpdateProfileColorQuery final : public Td::ResultHandler { - Promise promise_; - AccentColorId accent_color_id_; - CustomEmojiId background_custom_emoji_id_; - - public: - explicit UpdateProfileColorQuery(Promise &&promise) : promise_(std::move(promise)) { - } - - void send(AccentColorId accent_color_id, CustomEmojiId background_custom_emoji_id) { - accent_color_id_ = accent_color_id; - background_custom_emoji_id_ = background_custom_emoji_id; - int32 flags = telegram_api::account_updateColor::FOR_PROFILE_MASK; - if (accent_color_id.is_valid()) { - flags |= telegram_api::account_updateColor::COLOR_MASK; - } - if (background_custom_emoji_id.is_valid()) { - flags |= telegram_api::account_updateColor::BACKGROUND_EMOJI_ID_MASK; - } - send_query(G()->net_query_creator().create( - telegram_api::account_updateColor(flags, false /*ignored*/, accent_color_id.get(), - background_custom_emoji_id.get()), - {{"me"}})); - } - - void on_result(BufferSlice packet) final { - auto result_ptr = fetch_result(packet); - if (result_ptr.is_error()) { - return on_error(result_ptr.move_as_error()); - } - - LOG(DEBUG) << "Receive result for UpdateProfileColorQuery: " << result_ptr.ok(); - td_->contacts_manager_->on_update_profile_accent_color_success(accent_color_id_, background_custom_emoji_id_); + td_->contacts_manager_->on_update_accent_color_success(for_profile_, accent_color_id_, background_custom_emoji_id_); promise_.set_value(Unit()); } @@ -7919,12 +7883,12 @@ void ContactsManager::set_accent_color(AccentColorId accent_color_id, CustomEmoj accent_color_id = AccentColorId(); } - td_->create_handler(std::move(promise))->send(accent_color_id, background_custom_emoji_id); + td_->create_handler(std::move(promise))->send(false, accent_color_id, background_custom_emoji_id); } void ContactsManager::set_profile_accent_color(AccentColorId accent_color_id, CustomEmojiId background_custom_emoji_id, Promise &&promise) { - td_->create_handler(std::move(promise))->send(accent_color_id, background_custom_emoji_id); + td_->create_handler(std::move(promise))->send(true, accent_color_id, background_custom_emoji_id); } void ContactsManager::set_name(const string &first_name, const string &last_name, Promise &&promise) { @@ -7974,27 +7938,20 @@ void ContactsManager::set_bio(const string &bio, Promise &&promise) { td_->create_handler(std::move(promise))->send(flags, "", "", new_bio); } -void ContactsManager::on_update_accent_color_success(AccentColorId accent_color_id, +void ContactsManager::on_update_accent_color_success(bool for_profile, AccentColorId accent_color_id, CustomEmojiId background_custom_emoji_id) { auto user_id = get_my_id(); User *u = get_user_force(user_id, "on_update_accent_color_success"); if (u == nullptr) { return; } - on_update_user_accent_color_id(u, user_id, accent_color_id); - on_update_user_background_custom_emoji_id(u, user_id, background_custom_emoji_id); - update_user(u, user_id); -} - -void ContactsManager::on_update_profile_accent_color_success(AccentColorId accent_color_id, - CustomEmojiId background_custom_emoji_id) { - auto user_id = get_my_id(); - User *u = get_user_force(user_id, "on_update_profile_accent_color_success"); - if (u == nullptr) { - return; + if (for_profile) { + on_update_user_profile_accent_color_id(u, user_id, accent_color_id); + on_update_user_profile_background_custom_emoji_id(u, user_id, background_custom_emoji_id); + } else { + on_update_user_accent_color_id(u, user_id, accent_color_id); + on_update_user_background_custom_emoji_id(u, user_id, background_custom_emoji_id); } - on_update_user_profile_accent_color_id(u, user_id, accent_color_id); - on_update_user_profile_background_custom_emoji_id(u, user_id, background_custom_emoji_id); update_user(u, user_id); } diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 783393573..f3a3410cd 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -209,8 +209,8 @@ class ContactsManager final : public Actor { void on_get_channel_full_failed(ChannelId channel_id); void on_update_profile_success(int32 flags, const string &first_name, const string &last_name, const string &about); - void on_update_accent_color_success(AccentColorId accent_color_id, CustomEmojiId background_custom_emoji_id); - void on_update_profile_accent_color_success(AccentColorId accent_color_id, CustomEmojiId background_custom_emoji_id); + void on_update_accent_color_success(bool for_profile, AccentColorId accent_color_id, + CustomEmojiId background_custom_emoji_id); void on_update_user_name(UserId user_id, string &&first_name, string &&last_name, Usernames &&usernames); void on_update_user_phone_number(UserId user_id, string &&phone_number);