From aef203ed0590971692ec6b685b16c7f6d43a407b Mon Sep 17 00:00:00 2001 From: levlam Date: Wed, 30 Nov 2022 16:53:01 +0300 Subject: [PATCH] Allow to change topic name and icon separately. --- td/generate/scheme/td_api.tl | 7 ++++--- td/telegram/ForumTopicManager.cpp | 21 ++++++++++++++------- td/telegram/ForumTopicManager.h | 2 +- td/telegram/Td.cpp | 4 ++-- td/telegram/cli.cpp | 6 ++++-- 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index f9cbdfa13..bf5ba7323 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -5324,9 +5324,10 @@ createForumTopic chat_id:int53 name:string icon:forumTopicIcon = ForumTopicInfo; //@description Edits title and icon of a topic in a forum supergroup chat; requires can_manage_topics administrator rights in the supergroup unless the user is creator of the topic //@chat_id Identifier of the chat //@message_thread_id Message thread identifier of the forum topic -//@name New name of the topic; 1-128 characters -//@icon_custom_emoji_id Identifier of the new custom emoji for topic icon. Telegram Premium users can use any custom emoji, other users can use only a custom emoji returned by getForumTopicDefaultIcons -editForumTopic chat_id:int53 message_thread_id:int53 name:string icon_custom_emoji_id:int64 = Ok; +//@name New name of the topic; 0-128 characters. If empty, the previous topic name is kept +//@edit_icon_custom_emoji Pass true to edit the icon of the topic +//@icon_custom_emoji_id Identifier of the new custom emoji for topic icon; pass 0 to remove the custom emoji. Ignored if edit_icon_custom_emoji is false. Telegram Premium users can use any custom emoji, other users can use only a custom emoji returned by getForumTopicDefaultIcons +editForumTopic chat_id:int53 message_thread_id:int53 name:string edit_icon_custom_emoji:Bool icon_custom_emoji_id:int64 = Ok; //@description Toggles whether a topic is closed in a forum supergroup chat; requires can_manage_topics administrator rights in the supergroup unless the user is creator of the topic //@chat_id Identifier of the chat diff --git a/td/telegram/ForumTopicManager.cpp b/td/telegram/ForumTopicManager.cpp index 9a7566eb5..66175a638 100644 --- a/td/telegram/ForumTopicManager.cpp +++ b/td/telegram/ForumTopicManager.cpp @@ -121,16 +121,21 @@ class EditForumTopicQuery final : public Td::ResultHandler { explicit EditForumTopicQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send(ChannelId channel_id, MessageId top_thread_message_id, const string &title, - CustomEmojiId icon_custom_emoji_id) { + void send(ChannelId channel_id, MessageId top_thread_message_id, bool edit_title, const string &title, + bool edit_custom_emoji_id, CustomEmojiId icon_custom_emoji_id) { channel_id_ = channel_id; top_thread_message_id_ = top_thread_message_id; auto input_channel = td_->contacts_manager_->get_input_channel(channel_id); CHECK(input_channel != nullptr); - int32 flags = - telegram_api::channels_editForumTopic::TITLE_MASK | telegram_api::channels_editForumTopic::ICON_EMOJI_ID_MASK; + int32 flags = 0; + if (edit_title) { + flags |= telegram_api::channels_editForumTopic::TITLE_MASK; + } + if (edit_custom_emoji_id) { + flags |= telegram_api::channels_editForumTopic::ICON_EMOJI_ID_MASK; + } send_query(G()->net_query_creator().create( telegram_api::channels_editForumTopic(flags, std::move(input_channel), top_thread_message_id.get_server_message_id().get(), title, @@ -257,7 +262,8 @@ void ForumTopicManager::on_forum_topic_created(DialogId dialog_id, unique_ptr &&promise) { + bool edit_icon_custom_emoji, CustomEmojiId icon_custom_emoji_id, + Promise &&promise) { TRY_STATUS_PROMISE(promise, is_forum(dialog_id)); auto channel_id = dialog_id.get_channel_id(); @@ -272,13 +278,14 @@ void ForumTopicManager::edit_forum_topic(DialogId dialog_id, MessageId top_threa } } + bool edit_title = !title.empty(); auto new_title = clean_name(std::move(title), MAX_FORUM_TOPIC_TITLE_LENGTH); - if (new_title.empty()) { + if (edit_title && new_title.empty()) { return promise.set_error(Status::Error(400, "Title must be non-empty")); } td_->create_handler(std::move(promise)) - ->send(channel_id, top_thread_message_id, new_title, icon_custom_emoji_id); + ->send(channel_id, top_thread_message_id, edit_title, new_title, edit_icon_custom_emoji, icon_custom_emoji_id); } void ForumTopicManager::toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id, diff --git a/td/telegram/ForumTopicManager.h b/td/telegram/ForumTopicManager.h index 875ea601a..eba822152 100644 --- a/td/telegram/ForumTopicManager.h +++ b/td/telegram/ForumTopicManager.h @@ -41,7 +41,7 @@ class ForumTopicManager final : public Actor { Promise> &&promise); void edit_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, string &&title, - CustomEmojiId icon_custom_emoji_id, Promise &&promise); + bool edit_icon_custom_emoji, CustomEmojiId icon_custom_emoji_id, Promise &&promise); void toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id, bool is_closed, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 2bbf370a8..5c3cb45a2 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5545,8 +5545,8 @@ void Td::on_request(uint64 id, td_api::editForumTopic &request) { CLEAN_INPUT_STRING(request.name_); CREATE_OK_REQUEST_PROMISE(); forum_topic_manager_->edit_forum_topic(DialogId(request.chat_id_), MessageId(request.message_thread_id_), - std::move(request.name_), CustomEmojiId(request.icon_custom_emoji_id_), - std::move(promise)); + std::move(request.name_), request.edit_icon_custom_emoji_, + CustomEmojiId(request.icon_custom_emoji_id_), std::move(promise)); } void Td::on_request(uint64 id, const td_api::toggleForumTopicIsClosed &request) { diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 46abbd7cc..5c7c270e4 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3873,9 +3873,11 @@ class CliClient final : public Actor { ChatId chat_id; MessageThreadId message_thread_id; string name; + bool edit_icon_custom_emoji; int64 icon_custom_emoji_id; - get_args(args, chat_id, message_thread_id, name, icon_custom_emoji_id); - send_request(td_api::make_object(chat_id, message_thread_id, name, icon_custom_emoji_id)); + get_args(args, chat_id, message_thread_id, name, edit_icon_custom_emoji, icon_custom_emoji_id); + send_request(td_api::make_object(chat_id, message_thread_id, name, edit_icon_custom_emoji, + icon_custom_emoji_id)); } else if (op == "tftic") { ChatId chat_id; MessageThreadId message_thread_id;