Add td_api::setChatProfileAccentColor.

This commit is contained in:
levlam 2023-12-17 23:34:58 +03:00
parent d6423f60be
commit 1393033fdf
8 changed files with 83 additions and 4 deletions

View File

@ -6462,7 +6462,7 @@ updateAccentColors colors:vector<accentColor> available_accent_color_ids:vector<
//@description The list of supported accent colors for user profiles has changed
//@colors Information about supported colors
//@available_accent_color_ids The list of accent color identifiers, which can be set through setProfileAccentColor. The colors must be shown in the specififed order
//@available_accent_color_ids The list of accent color identifiers, which can be set through setProfileAccentColor and setChatProfileAccentColor. The colors must be shown in the specififed order
updateProfileAccentColors colors:vector<profileAccentColor> available_accent_color_ids:vector<int32> = Update;
//@description Some language pack strings have been updated @localization_target Localization target to which the language pack belongs @language_pack_id Identifier of the updated language pack @strings List of changed language pack strings; empty if all strings have changed
@ -7837,6 +7837,12 @@ setChatPhoto chat_id:int53 photo:InputChatPhoto = Ok;
//@background_custom_emoji_id Identifier of a custom emoji to be shown on the reply header background; 0 if none
setChatAccentColor chat_id:int53 accent_color_id:int32 background_custom_emoji_id:int64 = Ok;
//@description Changes accent color and background custom emoji for profile of a chat. Supported only for channels with getOption("channel_custom_profile_accent_color_boost_level_min") boost level. Requires can_change_info administrator right
//@chat_id Chat identifier
//@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 on the chat's profile photo background; 0 if none
setChatProfileAccentColor chat_id:int53 profile_accent_color_id:int32 profile_background_custom_emoji_id:int64 = Ok;
//@description Changes the message auto-delete or self-destruct (for secret chats) time in a chat. Requires change_info administrator right in basic groups, supergroups and channels
//-Message auto-delete time can't be changed in a chat with the current user (Saved Messages) and the chat 777000 (Telegram).
//@chat_id Chat identifier
@ -8797,7 +8803,7 @@ 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
//@profile_background_custom_emoji_id Identifier of a custom emoji to be shown 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

View File

@ -1333,11 +1333,15 @@ class UpdateChannelColorQuery final : public Td::ResultHandler {
explicit UpdateChannelColorQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId channel_id, AccentColorId accent_color_id, CustomEmojiId background_custom_emoji_id) {
void send(ChannelId channel_id, bool for_profile, AccentColorId accent_color_id,
CustomEmojiId background_custom_emoji_id) {
channel_id_ = channel_id;
auto input_channel = td_->contacts_manager_->get_input_channel(channel_id);
CHECK(input_channel != nullptr);
int32 flags = 0;
if (for_profile) {
flags |= telegram_api::channels_updateColor::FOR_PROFILE_MASK;
}
if (accent_color_id.is_valid()) {
flags |= telegram_api::channels_updateColor::COLOR_MASK;
}
@ -8237,7 +8241,25 @@ void ContactsManager::set_channel_accent_color(ChannelId channel_id, AccentColor
}
td_->create_handler<UpdateChannelColorQuery>(std::move(promise))
->send(channel_id, accent_color_id, background_custom_emoji_id);
->send(channel_id, false, accent_color_id, background_custom_emoji_id);
}
void ContactsManager::set_channel_profile_accent_color(ChannelId channel_id, AccentColorId profile_accent_color_id,
CustomEmojiId profile_background_custom_emoji_id,
Promise<Unit> &&promise) {
const auto *c = get_channel(channel_id);
if (c == nullptr) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
if (c->is_megagroup) {
return promise.set_error(Status::Error(400, "Accent color can be changed only in channel chats"));
}
if (!get_channel_status(c).can_change_info_and_settings()) {
return promise.set_error(Status::Error(400, "Not enough rights in the channel"));
}
td_->create_handler<UpdateChannelColorQuery>(std::move(promise))
->send(channel_id, true, profile_accent_color_id, profile_background_custom_emoji_id);
}
void ContactsManager::set_channel_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id,

View File

@ -477,6 +477,9 @@ class ContactsManager final : public Actor {
void set_channel_accent_color(ChannelId channel_id, AccentColorId accent_color_id,
CustomEmojiId background_custom_emoji_id, Promise<Unit> &&promise);
void set_channel_profile_accent_color(ChannelId channel_id, AccentColorId profile_accent_color_id,
CustomEmojiId profile_background_custom_emoji_id, Promise<Unit> &&promise);
void set_channel_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id, Promise<Unit> &&promise);
void toggle_channel_sign_messages(ChannelId channel_id, bool sign_messages, Promise<Unit> &&promise);

View File

@ -34087,6 +34087,34 @@ void MessagesManager::set_dialog_accent_color(DialogId dialog_id, AccentColorId
promise.set_error(Status::Error(400, "Can't change accent color in the chat"));
}
void MessagesManager::set_dialog_profile_accent_color(DialogId dialog_id, AccentColorId profile_accent_color_id,
CustomEmojiId profile_background_custom_emoji_id,
Promise<Unit> &&promise) {
if (!have_dialog_force(dialog_id, "set_dialog_profile_accent_color")) {
return promise.set_error(Status::Error(400, "Chat not found"));
}
switch (dialog_id.get_type()) {
case DialogType::User:
if (dialog_id == get_my_dialog_id()) {
return td_->contacts_manager_->set_profile_accent_color(profile_accent_color_id,
profile_background_custom_emoji_id, std::move(promise));
}
break;
case DialogType::Chat:
break;
case DialogType::Channel:
return td_->contacts_manager_->set_channel_profile_accent_color(
dialog_id.get_channel_id(), profile_accent_color_id, profile_background_custom_emoji_id, std::move(promise));
case DialogType::SecretChat:
break;
case DialogType::None:
default:
UNREACHABLE();
}
promise.set_error(Status::Error(400, "Can't change profile accent color in the chat"));
}
void MessagesManager::set_dialog_title(DialogId dialog_id, const string &title, Promise<Unit> &&promise) {
if (!have_dialog_force(dialog_id, "set_dialog_title")) {
return promise.set_error(Status::Error(400, "Chat not found"));

View File

@ -564,6 +564,9 @@ class MessagesManager final : public Actor {
void set_dialog_accent_color(DialogId dialog_id, AccentColorId accent_color_id,
CustomEmojiId background_custom_emoji_id, Promise<Unit> &&promise);
void set_dialog_profile_accent_color(DialogId dialog_id, AccentColorId profile_accent_color_id,
CustomEmojiId profile_background_custom_emoji_id, Promise<Unit> &&promise);
void set_dialog_description(DialogId dialog_id, const string &description, Promise<Unit> &&promise);
void set_active_reactions(vector<ReactionType> active_reaction_types);

View File

@ -6520,6 +6520,14 @@ void Td::on_request(uint64 id, const td_api::setChatAccentColor &request) {
CustomEmojiId(request.background_custom_emoji_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setChatProfileAccentColor &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
messages_manager_->set_dialog_profile_accent_color(
DialogId(request.chat_id_), AccentColorId(request.profile_accent_color_id_),
CustomEmojiId(request.profile_background_custom_emoji_id_), std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setChatMessageAutoDeleteTime &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();

View File

@ -1011,6 +1011,8 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::setChatAccentColor &request);
void on_request(uint64 id, const td_api::setChatProfileAccentColor &request);
void on_request(uint64 id, const td_api::setChatMessageAutoDeleteTime &request);
void on_request(uint64 id, const td_api::setChatPermissions &request);

View File

@ -5337,6 +5337,13 @@ class CliClient final : public Actor {
get_args(args, chat_id, accent_color_id, background_custom_emoji_id);
send_request(
td_api::make_object<td_api::setChatAccentColor>(chat_id, accent_color_id, background_custom_emoji_id));
} else if (op == "scpac") {
ChatId chat_id;
int32 profile_accent_color_id;
CustomEmojiId profile_background_custom_emoji_id;
get_args(args, chat_id, profile_accent_color_id, profile_background_custom_emoji_id);
send_request(td_api::make_object<td_api::setChatProfileAccentColor>(chat_id, profile_accent_color_id,
profile_background_custom_emoji_id));
} else if (op == "scmt") {
ChatId chat_id;
int32 auto_delete_time;