Add td_api::setChatAccentColor.

This commit is contained in:
levlam 2023-10-18 19:43:14 +03:00
parent 6ec7ab73e5
commit f78bc2ae32
8 changed files with 122 additions and 0 deletions

View File

@ -7606,6 +7606,12 @@ setChatTitle chat_id:int53 title:string = Ok;
//@photo New chat photo; pass null to delete the chat photo
setChatPhoto chat_id:int53 photo:InputChatPhoto = Ok;
//@description Changes accent color and background custom emoji of a chat. Supported only for channels with getOption("channel_custom_accent_color_boost_level_min") boost level. Requires can_change_info administrator right
//@chat_id Chat identifier
//@accent_color_id Identifier of the accent color to use
//@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 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

View File

@ -1314,6 +1314,52 @@ class ReorderChannelUsernamesQuery final : public Td::ResultHandler {
}
};
class UpdateChannelColorQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
public:
explicit UpdateChannelColorQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(ChannelId channel_id, 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 (background_custom_emoji_id.is_valid()) {
flags |= telegram_api::channels_updateColor::BACKGROUND_EMOJI_ID_MASK;
}
send_query(G()->net_query_creator().create(
telegram_api::channels_updateColor(flags, std::move(input_channel), accent_color_id.get(),
background_custom_emoji_id.get()),
{{channel_id}}));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::channels_updateColor>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for UpdateChannelColorQuery: " << to_string(ptr);
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(Status status) final {
if (status.message() == "CHAT_NOT_MODIFIED") {
if (!td_->auth_manager_->is_bot()) {
promise_.set_value(Unit());
return;
}
} else {
td_->contacts_manager_->on_get_channel_error(channel_id_, status, "UpdateChannelColorQuery");
}
promise_.set_error(std::move(status));
}
};
class SetChannelStickerSetQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
ChannelId channel_id_;
@ -7942,6 +7988,27 @@ void ContactsManager::on_update_channel_active_usernames_order(ChannelId channel
promise.set_value(Unit());
}
void ContactsManager::set_channel_accent_color(ChannelId channel_id, AccentColorId accent_color_id,
CustomEmojiId background_custom_emoji_id, Promise<Unit> &&promise) {
if (!accent_color_id.is_valid()) {
return promise.set_error(Status::Error(400, "Invalid accent color identifier specified"));
}
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, accent_color_id, background_custom_emoji_id);
}
void ContactsManager::set_channel_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id,
Promise<Unit> &&promise) {
auto c = get_channel(channel_id);

View File

@ -457,6 +457,9 @@ class ContactsManager final : public Actor {
void reorder_channel_usernames(ChannelId channel_id, vector<string> &&usernames, Promise<Unit> &&promise);
void set_channel_accent_color(ChannelId channel_id, AccentColorId accent_color_id,
CustomEmojiId 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

@ -33585,6 +33585,33 @@ void MessagesManager::upload_dialog_photo(DialogId dialog_id, FileId file_id, bo
td_->file_manager_->resume_upload(file_id, std::move(bad_parts), upload_dialog_photo_callback_, 32, 0);
}
void MessagesManager::set_dialog_accent_color(DialogId dialog_id, AccentColorId accent_color_id,
CustomEmojiId background_custom_emoji_id, Promise<Unit> &&promise) {
if (!have_dialog_force(dialog_id, "set_dialog_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_accent_color(accent_color_id, background_custom_emoji_id,
std::move(promise));
}
break;
case DialogType::Chat:
break;
case DialogType::Channel:
return td_->contacts_manager_->set_channel_accent_color(dialog_id.get_channel_id(), accent_color_id,
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 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

@ -547,6 +547,9 @@ class MessagesManager final : public Actor {
void set_dialog_title(DialogId dialog_id, const string &title, Promise<Unit> &&promise);
void set_dialog_accent_color(DialogId dialog_id, AccentColorId accent_color_id,
CustomEmojiId 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

@ -6465,6 +6465,13 @@ void Td::on_request(uint64 id, const td_api::setChatPhoto &request) {
messages_manager_->set_dialog_photo(DialogId(request.chat_id_), request.photo_, std::move(promise));
}
void Td::on_request(uint64 id, const td_api::setChatAccentColor &request) {
CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE();
messages_manager_->set_dialog_accent_color(DialogId(request.chat_id_), AccentColorId(request.accent_color_id_),
CustomEmojiId(request.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

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

View File

@ -5261,6 +5261,13 @@ class CliClient final : public Actor {
InputChatPhoto input_chat_photo;
get_args(args, chat_id, input_chat_photo);
send_request(td_api::make_object<td_api::setChatPhoto>(chat_id, input_chat_photo));
} else if (op == "scac") {
ChatId chat_id;
int32 accent_color_id;
CustomEmojiId background_custom_emoji_id;
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 == "scmt") {
ChatId chat_id;
int32 auto_delete_time;