Add td_api::setProfileAccentColor.

This commit is contained in:
levlam 2023-11-28 16:12:21 +03:00
parent 45ca900759
commit 9fbdba456a
6 changed files with 83 additions and 0 deletions

View File

@ -8707,6 +8707,11 @@ deleteProfilePhoto profile_photo_id:int64 = Ok;
//@background_custom_emoji_id Identifier of a custom emoji to be shown on the reply header background; 0 if none
setAccentColor accent_color_id:int32 background_custom_emoji_id:int64 = Ok;
//@description Changes accent color and background custom emoji for profile of the current user; for Telegram Premium users only
//@profile_accent_color_id Identifier of the accent color to use for profile; pass -1 if none
//@profile_background_custom_emoji_id Identifier of a custom emoji to be shown in the on the user's profile photo background; 0 if none
setProfileAccentColor profile_accent_color_id:int32 profile_background_custom_emoji_id:int64 = Ok;
//@description Changes the first and last name of the current user @first_name The new value of the first name for the current user; 1-64 characters @last_name The new value of the optional last name for the current user; 0-64 characters
setName first_name:string last_name:string = Ok;

View File

@ -812,6 +812,47 @@ class UpdateColorQuery final : public Td::ResultHandler {
}
};
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 UpdateColorQuery: " << result_ptr.ok();
td_->contacts_manager_->on_update_profile_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 UpdateProfileQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
int32 flags_;
@ -7796,6 +7837,11 @@ void ContactsManager::set_accent_color(AccentColorId accent_color_id, CustomEmoj
td_->create_handler<UpdateColorQuery>(std::move(promise))->send(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);
}
void ContactsManager::set_name(const string &first_name, const string &last_name, Promise<Unit> &&promise) {
auto new_first_name = clean_name(first_name, MAX_NAME_LENGTH);
auto new_last_name = clean_name(last_name, MAX_NAME_LENGTH);
@ -7855,6 +7901,18 @@ void ContactsManager::on_update_accent_color_success(AccentColorId accent_color_
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;
}
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);
}
void ContactsManager::on_update_profile_success(int32 flags, const string &first_name, const string &last_name,
const string &about) {
CHECK(flags != 0);

View File

@ -200,6 +200,7 @@ class ContactsManager final : public Actor {
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_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);
@ -433,6 +434,9 @@ class ContactsManager final : public Actor {
void set_accent_color(AccentColorId accent_color_id, CustomEmojiId background_custom_emoji_id,
Promise<Unit> &&promise);
void set_profile_accent_color(AccentColorId accent_color_id, CustomEmojiId background_custom_emoji_id,
Promise<Unit> &&promise);
void set_name(const string &first_name, const string &last_name, Promise<Unit> &&promise);
void set_bio(const string &bio, Promise<Unit> &&promise);

View File

@ -7622,6 +7622,14 @@ void Td::on_request(uint64 id, const td_api::setAccentColor &request) {
CustomEmojiId(request.background_custom_emoji_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setProfileAccentColor &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
contacts_manager_->set_profile_accent_color(AccentColorId(request.profile_accent_color_id_),
CustomEmojiId(request.profile_background_custom_emoji_id_),
std::move(promise));
}
void Td::on_request(uint64 id, td_api::setSupergroupUsername &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.username_);

View File

@ -1293,6 +1293,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::setAccentColor &request);
void on_request(uint64 id, const td_api::setProfileAccentColor &request);
void on_request(uint64 id, td_api::setSupergroupUsername &request);
void on_request(uint64 id, td_api::toggleSupergroupUsernameIsActive &request);

View File

@ -5871,6 +5871,12 @@ class CliClient final : public Actor {
CustomEmojiId background_custom_emoji_id;
get_args(args, accent_color_id, background_custom_emoji_id);
send_request(td_api::make_object<td_api::setAccentColor>(accent_color_id, background_custom_emoji_id));
} else if (op == "spac") {
int32 profile_accent_color_id;
CustomEmojiId profile_background_custom_emoji_id;
get_args(args, profile_accent_color_id, profile_background_custom_emoji_id);
send_request(td_api::make_object<td_api::setProfileAccentColor>(profile_accent_color_id,
profile_background_custom_emoji_id));
} else if (op == "gns") {
int64 notification_sound_id;
get_args(args, notification_sound_id);