From 99e6629c79a8af7fcf5ad928a41a6476950591f6 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 27 Oct 2022 17:31:05 +0300 Subject: [PATCH] Add toggleForumTopicIsClosed. --- td/generate/scheme/td_api.tl | 6 ++++++ td/telegram/ForumTopicManager.cpp | 31 +++++++++++++++++++++++++++++++ td/telegram/ForumTopicManager.h | 3 +++ td/telegram/Td.cpp | 7 +++++++ td/telegram/Td.h | 2 ++ td/telegram/cli.cpp | 6 ++++++ 6 files changed, 55 insertions(+) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 9f5657497..823df3824 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -5307,6 +5307,12 @@ createForumTopic chat_id:int53 title:string icon:forumTopicIcon = ForumTopicInfo //@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 title:string icon_custom_emoji_id:int64 = Ok; +//@description Toggles is_closed state of a topic in a forum supergroup chat; requires can_manage_topics administrator rights in the supergroup +//@chat_id Identifier of the chat +//@message_thread_id Message thread identifier of the forum topic +//@is_closed Pass true to close the topic; pass false to open it +toggleForumTopicIsClosed chat_id:int53 message_thread_id:int53 is_closed:Bool = Ok; + //@description Returns information about a emoji reaction. Returns a 404 error if the reaction is not found @emoji Text representation of the reaction getEmojiReaction emoji:string = EmojiReaction; diff --git a/td/telegram/ForumTopicManager.cpp b/td/telegram/ForumTopicManager.cpp index ec54e0b26..fe79b8ea8 100644 --- a/td/telegram/ForumTopicManager.cpp +++ b/td/telegram/ForumTopicManager.cpp @@ -131,6 +131,21 @@ class EditForumTopicQuery final : public Td::ResultHandler { {{channel_id}})); } + void send(ChannelId channel_id, MessageId top_thread_message_id, bool is_closed) { + 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::CLOSED_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(), string(), 0, + is_closed), + {{channel_id}})); + } + void on_result(BufferSlice packet) final { auto result_ptr = fetch_result(packet); if (result_ptr.is_error()) { @@ -233,6 +248,22 @@ void ForumTopicManager::edit_forum_topic(DialogId dialog_id, MessageId top_threa ->send(channel_id, top_thread_message_id, new_title, icon_custom_emoji_id); } +void ForumTopicManager::toggle_forum_topic_is_closed(DialogId dialog_id, MessageId top_thread_message_id, + bool is_closed, Promise &&promise) { + TRY_STATUS_PROMISE(promise, is_forum(dialog_id)); + auto channel_id = dialog_id.get_channel_id(); + + if (!top_thread_message_id.is_valid() || !top_thread_message_id.is_server()) { + return promise.set_error(Status::Error(400, "Invalid message thread identifier specified")); + } + + if (!td_->contacts_manager_->get_channel_permissions(channel_id).can_edit_topics()) { + return promise.set_error(Status::Error(400, "Not enough rights to edit a topic")); + } + + td_->create_handler(std::move(promise))->send(channel_id, top_thread_message_id, is_closed); +} + Status ForumTopicManager::is_forum(DialogId dialog_id) { if (!td_->messages_manager_->have_dialog_force(dialog_id, "ForumTopicManager::is_forum")) { return Status::Error(400, "Chat not found"); diff --git a/td/telegram/ForumTopicManager.h b/td/telegram/ForumTopicManager.h index e7884faaa..3019eb15e 100644 --- a/td/telegram/ForumTopicManager.h +++ b/td/telegram/ForumTopicManager.h @@ -39,6 +39,9 @@ class ForumTopicManager final : public Actor { void edit_forum_topic(DialogId dialog_id, MessageId top_thread_message_id, string &&title, 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); + private: static constexpr size_t MAX_FORUM_TOPIC_TITLE_LENGTH = 128; // server side limit for forum topic title diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 25a0b630d..f1d0b4a0d 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5532,6 +5532,13 @@ void Td::on_request(uint64 id, td_api::editForumTopic &request) { std::move(promise)); } +void Td::on_request(uint64 id, const td_api::toggleForumTopicIsClosed &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + forum_topic_manager_->toggle_forum_topic_is_closed(DialogId(request.chat_id_), MessageId(request.message_thread_id_), + request.is_closed_, std::move(promise)); +} + void Td::on_request(uint64 id, td_api::setGameScore &request) { CHECK_IS_BOT(); CREATE_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 58acd5982..1d7bebd87 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -736,6 +736,8 @@ class Td final : public Actor { void on_request(uint64 id, td_api::editForumTopic &request); + void on_request(uint64 id, const td_api::toggleForumTopicIsClosed &request); + void on_request(uint64 id, td_api::setGameScore &request); void on_request(uint64 id, td_api::setInlineGameScore &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index e0f5d967a..5c46586eb 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3871,6 +3871,12 @@ class CliClient final : public Actor { get_args(args, chat_id, message_thread_id, title, icon_custom_emoji_id); send_request( td_api::make_object(chat_id, message_thread_id, title, icon_custom_emoji_id)); + } else if (op == "tftic") { + ChatId chat_id; + MessageThreadId message_thread_id; + bool is_closed; + get_args(args, chat_id, message_thread_id, is_closed); + send_request(td_api::make_object(chat_id, message_thread_id, is_closed)); } else if (op == "gallm") { send_request(td_api::make_object()); } else if (op == "sbsm") {