Remove separate UpdateProfileColorQuery.

This commit is contained in:
levlam 2023-12-17 23:12:03 +03:00
parent 7ceccad807
commit d6423f60be
2 changed files with 18 additions and 61 deletions

View File

@ -775,6 +775,7 @@ class DeleteProfilePhotoQuery final : public Td::ResultHandler {
class UpdateColorQuery final : public Td::ResultHandler {
Promise<Unit> 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<Unit> &&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<Unit> promise_;
AccentColorId accent_color_id_;
CustomEmojiId background_custom_emoji_id_;
public:
explicit UpdateProfileColorQuery(Promise<Unit> &&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<telegram_api::account_updateColor>(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<UpdateColorQuery>(std::move(promise))->send(accent_color_id, background_custom_emoji_id);
td_->create_handler<UpdateColorQuery>(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<Unit> &&promise) {
td_->create_handler<UpdateProfileColorQuery>(std::move(promise))->send(accent_color_id, background_custom_emoji_id);
td_->create_handler<UpdateColorQuery>(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<Unit> &&promise) {
@ -7974,27 +7938,20 @@ void ContactsManager::set_bio(const string &bio, Promise<Unit> &&promise) {
td_->create_handler<UpdateProfileQuery>(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);
}
update_user(u, user_id);
}

View File

@ -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);