From 849d48e858d87fce9cd7971d4c99846237d058d2 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 29 Dec 2022 21:02:15 +0300 Subject: [PATCH] Add methods for General topic management. --- telegram-bot-api/Client.cpp | 59 +++++++++++++++++++++++++++++++++++++ telegram-bot-api/Client.h | 7 +++++ 2 files changed, 66 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index dfbfedf..678433c 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -268,6 +268,11 @@ bool Client::init_methods() { methods_.emplace("reopenforumtopic", &Client::process_reopen_forum_topic_query); methods_.emplace("deleteforumtopic", &Client::process_delete_forum_topic_query); methods_.emplace("unpinallforumtopicmessages", &Client::process_unpin_all_forum_topic_messages_query); + methods_.emplace("editgeneralforumtopic", &Client::process_edit_general_forum_topic_query); + methods_.emplace("closegeneralforumtopic", &Client::process_close_general_forum_topic_query); + methods_.emplace("reopengeneralforumtopic", &Client::process_reopen_general_forum_topic_query); + methods_.emplace("hidegeneralforumtopic", &Client::process_hide_general_forum_topic_query); + methods_.emplace("unhidegeneralforumtopic", &Client::process_unhide_general_forum_topic_query); methods_.emplace("getchatmember", &Client::process_get_chat_member_query); methods_.emplace("getchatadministrators", &Client::process_get_chat_administrators_query); methods_.emplace("getchatmembercount", &Client::process_get_chat_member_count_query); @@ -8435,6 +8440,58 @@ td::Status Client::process_unpin_all_forum_topic_messages_query(PromisedQueryPtr return Status::OK(); } +td::Status Client::process_edit_general_forum_topic_query(PromisedQueryPtr &query) { + auto chat_id = query->arg("chat_id"); + auto name = query->arg("name"); + + check_chat(chat_id, AccessRights::Write, std::move(query), + [this, name = name.str()](int64 chat_id, PromisedQueryPtr query) { + send_request(make_object(chat_id, GENERAL_MESSAGE_THREAD_ID, name, false, 0), + td::make_unique(std::move(query))); + }); + return Status::OK(); +} + +td::Status Client::process_close_general_forum_topic_query(PromisedQueryPtr &query) { + auto chat_id = query->arg("chat_id"); + + check_chat(chat_id, AccessRights::Write, std::move(query), [this](int64 chat_id, PromisedQueryPtr query) { + send_request(make_object(chat_id, GENERAL_MESSAGE_THREAD_ID, true), + td::make_unique(std::move(query))); + }); + return Status::OK(); +} + +td::Status Client::process_reopen_general_forum_topic_query(PromisedQueryPtr &query) { + auto chat_id = query->arg("chat_id"); + + check_chat(chat_id, AccessRights::Write, std::move(query), [this](int64 chat_id, PromisedQueryPtr query) { + send_request(make_object(chat_id, GENERAL_MESSAGE_THREAD_ID, false), + td::make_unique(std::move(query))); + }); + return Status::OK(); +} + +td::Status Client::process_hide_general_forum_topic_query(PromisedQueryPtr &query) { + auto chat_id = query->arg("chat_id"); + + check_chat(chat_id, AccessRights::Write, std::move(query), [this](int64 chat_id, PromisedQueryPtr query) { + send_request(make_object(chat_id, true), + td::make_unique(std::move(query))); + }); + return Status::OK(); +} + +td::Status Client::process_unhide_general_forum_topic_query(PromisedQueryPtr &query) { + auto chat_id = query->arg("chat_id"); + + check_chat(chat_id, AccessRights::Write, std::move(query), [this](int64 chat_id, PromisedQueryPtr query) { + send_request(make_object(chat_id, false), + td::make_unique(std::move(query))); + }); + return Status::OK(); +} + td::Status Client::process_get_chat_member_query(PromisedQueryPtr &query) { auto chat_id = query->arg("chat_id"); TRY_RESULT(user_id, get_user_id(query.get())); @@ -11035,6 +11092,8 @@ td::int64 Client::get_basic_group_chat_id(int64 basic_group_id) { return -basic_group_id; } +constexpr Client::int64 Client::GENERAL_MESSAGE_THREAD_ID; + constexpr Client::int64 Client::GREAT_MINDS_SET_ID; constexpr Client::Slice Client::GREAT_MINDS_SET_NAME; diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 6e367d5..8ad0e21 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -68,6 +68,8 @@ class Client final : public WebhookActor::Callback { static constexpr bool USE_MESSAGE_DATABASE = false; + static constexpr int64 GENERAL_MESSAGE_THREAD_ID = 1 << 20; + static constexpr int32 MAX_CERTIFICATE_FILE_SIZE = 3 << 20; static constexpr int32 MAX_DOWNLOAD_FILE_SIZE = 20 << 20; @@ -540,6 +542,11 @@ class Client final : public WebhookActor::Callback { Status process_reopen_forum_topic_query(PromisedQueryPtr &query); Status process_delete_forum_topic_query(PromisedQueryPtr &query); Status process_unpin_all_forum_topic_messages_query(PromisedQueryPtr &query); + Status process_edit_general_forum_topic_query(PromisedQueryPtr &query); + Status process_close_general_forum_topic_query(PromisedQueryPtr &query); + Status process_reopen_general_forum_topic_query(PromisedQueryPtr &query); + Status process_hide_general_forum_topic_query(PromisedQueryPtr &query); + Status process_unhide_general_forum_topic_query(PromisedQueryPtr &query); Status process_get_chat_member_query(PromisedQueryPtr &query); Status process_get_chat_administrators_query(PromisedQueryPtr &query); Status process_get_chat_member_count_query(PromisedQueryPtr &query);