From 1393033fdf6a9bc54e165ac3cbd9753e3123543d Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 17 Dec 2023 23:34:58 +0300 Subject: [PATCH] Add td_api::setChatProfileAccentColor. --- td/generate/scheme/td_api.tl | 10 ++++++++-- td/telegram/ContactsManager.cpp | 26 ++++++++++++++++++++++++-- td/telegram/ContactsManager.h | 3 +++ td/telegram/MessagesManager.cpp | 28 ++++++++++++++++++++++++++++ td/telegram/MessagesManager.h | 3 +++ td/telegram/Td.cpp | 8 ++++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 7 +++++++ 8 files changed, 83 insertions(+), 4 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 283b55f76..67a6efa35 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -6462,7 +6462,7 @@ updateAccentColors colors:vector 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 available_accent_color_ids:vector = 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 diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index f4c8bb6b2..215756817 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1333,11 +1333,15 @@ class UpdateChannelColorQuery final : public Td::ResultHandler { explicit UpdateChannelColorQuery(Promise &&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(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 &&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(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, diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index f3a3410cd..8b25cd854 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -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 &&promise); + void set_channel_profile_accent_color(ChannelId channel_id, AccentColorId profile_accent_color_id, + CustomEmojiId profile_background_custom_emoji_id, Promise &&promise); + void set_channel_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id, Promise &&promise); void toggle_channel_sign_messages(ChannelId channel_id, bool sign_messages, Promise &&promise); diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 7422fde43..733247c00 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -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 &&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 &&promise) { if (!have_dialog_force(dialog_id, "set_dialog_title")) { return promise.set_error(Status::Error(400, "Chat not found")); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index ea1b28c4a..076464fd3 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -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 &&promise); + void set_dialog_profile_accent_color(DialogId dialog_id, AccentColorId profile_accent_color_id, + CustomEmojiId profile_background_custom_emoji_id, Promise &&promise); + void set_dialog_description(DialogId dialog_id, const string &description, Promise &&promise); void set_active_reactions(vector active_reaction_types); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index cd4733167..de0068bbf 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -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(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 8f7ab776d..9cad51e74 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -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); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 1186d2b74..ecac5d13c 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -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(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(chat_id, profile_accent_color_id, + profile_background_custom_emoji_id)); } else if (op == "scmt") { ChatId chat_id; int32 auto_delete_time;