From f0d0ac6b788762bcdc13e41125c66cfcc465064c Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 9 Jan 2023 21:43:51 +0300 Subject: [PATCH] Allow to create forum supergroups. --- td/generate/scheme/td_api.tl | 5 +++-- td/telegram/MessagesManager.cpp | 17 ++++++++++------- td/telegram/MessagesManager.h | 2 +- td/telegram/Td.cpp | 11 +++++++---- td/telegram/cli.cpp | 12 ++++++++---- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index ebc2351e3..13f052fbd 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -6437,12 +6437,13 @@ createNewBasicGroupChat user_ids:vector title:string message_auto_delete_ //@description Creates a new supergroup or channel and sends a corresponding messageSupergroupChatCreate. Returns the newly created chat //@title Title of the new chat; 1-128 characters -//@is_channel Pass true to create a channel chat +//@is_forum Pass true to create a forum supergroup chat +//@is_channel Pass true to create a channel chat; ignored if a forum is created //@param_description Chat description; 0-255 characters //@location Chat location if a location-based supergroup is being created; pass null to create an ordinary supergroup chat //@message_auto_delete_time Message auto-delete time value, in seconds; must be from 0 up to 365 * 86400 and be divisible by 86400. If 0, then messages aren't deleted automatically //@for_import Pass true to create a supergroup for importing messages using importMessage -createNewSupergroupChat title:string is_channel:Bool description:string location:chatLocation message_auto_delete_time:int32 for_import:Bool = Chat; +createNewSupergroupChat title:string is_forum:Bool is_channel:Bool description:string location:chatLocation message_auto_delete_time:int32 for_import:Bool = Chat; //@description Creates a new secret chat. Returns the newly created chat @user_id Identifier of the target user createNewSecretChat user_id:int53 = Chat; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 6eabdc2f1..ee5f52193 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -1037,10 +1037,12 @@ class CreateChannelQuery final : public Td::ResultHandler { explicit CreateChannelQuery(Promise &&promise) : promise_(std::move(promise)) { } - void send(const string &title, bool is_megagroup, const string &about, const DialogLocation &location, + void send(const string &title, bool is_forum, bool is_megagroup, const string &about, const DialogLocation &location, bool for_import, MessageTtl message_ttl, int64 random_id) { int32 flags = telegram_api::channels_createChannel::TTL_PERIOD_MASK; - if (is_megagroup) { + if (is_forum) { + flags |= telegram_api::channels_createChannel::FORUM_MASK; + } else if (is_megagroup) { flags |= telegram_api::channels_createChannel::MEGAGROUP_MASK; } else { flags |= telegram_api::channels_createChannel::BROADCAST_MASK; @@ -21155,9 +21157,10 @@ DialogId MessagesManager::create_new_group_chat(const vector &user_ids, return DialogId(); } -DialogId MessagesManager::create_new_channel_chat(const string &title, bool is_megagroup, const string &description, - const DialogLocation &location, bool for_import, - MessageTtl message_ttl, int64 &random_id, Promise &&promise) { +DialogId MessagesManager::create_new_channel_chat(const string &title, bool is_forum, bool is_megagroup, + const string &description, const DialogLocation &location, + bool for_import, MessageTtl message_ttl, int64 &random_id, + Promise &&promise) { LOG(INFO) << "Trying to create " << (is_megagroup ? "supergroup" : "broadcast") << " with title \"" << title << "\", description \"" << description << "\" and " << location; @@ -21190,8 +21193,8 @@ DialogId MessagesManager::create_new_channel_chat(const string &title, bool is_m created_dialogs_[random_id]; // reserve place for result td_->create_handler(std::move(promise)) - ->send(new_title, is_megagroup, strip_empty_characters(description, MAX_DESCRIPTION_LENGTH), location, for_import, - message_ttl, random_id); + ->send(new_title, is_forum, is_megagroup, strip_empty_characters(description, MAX_DESCRIPTION_LENGTH), location, + for_import, message_ttl, random_id); return DialogId(); } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index cc094862b..26d380a15 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -692,7 +692,7 @@ class MessagesManager final : public Actor { DialogId create_new_group_chat(const vector &user_ids, const string &title, MessageTtl message_ttl, int64 &random_id, Promise &&promise); - DialogId create_new_channel_chat(const string &title, bool is_megagroup, const string &description, + DialogId create_new_channel_chat(const string &title, bool is_forum, bool is_megagroup, const string &description, const DialogLocation &location, bool for_import, MessageTtl message_ttl, int64 &random_id, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index f05ae9e7d..6653acda2 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -1683,6 +1683,7 @@ class CreateNewSecretChatRequest final : public RequestActor { class CreateNewSupergroupChatRequest final : public RequestActor<> { string title_; + bool is_forum_; bool is_megagroup_; string description_; DialogLocation location_; @@ -1693,8 +1694,9 @@ class CreateNewSupergroupChatRequest final : public RequestActor<> { DialogId dialog_id_; void do_run(Promise &&promise) final { - dialog_id_ = td_->messages_manager_->create_new_channel_chat( - title_, is_megagroup_, description_, location_, for_import_, message_ttl_, random_id_, std::move(promise)); + dialog_id_ = + td_->messages_manager_->create_new_channel_chat(title_, is_forum_, is_megagroup_, description_, location_, + for_import_, message_ttl_, random_id_, std::move(promise)); } void do_send_result() final { @@ -1703,11 +1705,12 @@ class CreateNewSupergroupChatRequest final : public RequestActor<> { } public: - CreateNewSupergroupChatRequest(ActorShared td, uint64 request_id, string title, bool is_megagroup, + CreateNewSupergroupChatRequest(ActorShared td, uint64 request_id, string title, bool is_forum, bool is_megagroup, string description, td_api::object_ptr &&location, bool for_import, int32 message_ttl) : RequestActor(std::move(td), request_id) , title_(std::move(title)) + , is_forum_(is_forum) , is_megagroup_(is_megagroup) , description_(std::move(description)) , location_(std::move(location)) @@ -5717,7 +5720,7 @@ void Td::on_request(uint64 id, td_api::createNewSupergroupChat &request) { CHECK_IS_USER(); CLEAN_INPUT_STRING(request.title_); CLEAN_INPUT_STRING(request.description_); - CREATE_REQUEST(CreateNewSupergroupChatRequest, std::move(request.title_), !request.is_channel_, + CREATE_REQUEST(CreateNewSupergroupChatRequest, std::move(request.title_), request.is_forum_, !request.is_channel_, std::move(request.description_), std::move(request.location_), request.for_import_, request.message_auto_delete_time_); } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 7628ef9a8..b9bbe4d71 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4340,17 +4340,21 @@ class CliClient final : public Actor { send_request(td_api::make_object(as_user_ids(user_ids_string), title, message_auto_delete_time)); } else if (op == "cnchc" || op == "cnchcadt") { - send_request(td_api::make_object(args, true, "Description", nullptr, + send_request(td_api::make_object(args, false, true, "Description", nullptr, op == "cnchcadt" ? 86400 : 0, false)); } else if (op == "cnsgc" || op == "cnsgcadt") { - send_request(td_api::make_object(args, false, "Description", nullptr, + send_request(td_api::make_object(args, false, false, "Description", nullptr, op == "cnsgcadt" ? 86400 : 0, false)); + } else if (op == "cnfc" || op == "cnfcadt") { + send_request(td_api::make_object(args, true, true, "Description", nullptr, + op == "cnfcadt" ? 86400 : 0, false)); } else if (op == "cnsgcloc") { send_request(td_api::make_object( - args, false, "Description", + args, false, false, "Description", td_api::make_object(as_location("40.0", "60.0", ""), "address"), 0, false)); } else if (op == "cnsgcimport") { - send_request(td_api::make_object(args, false, "Description", nullptr, 0, true)); + send_request( + td_api::make_object(args, false, false, "Description", nullptr, 0, true)); } else if (op == "UpgradeBasicGroupChatToSupergroupChat") { ChatId chat_id; get_args(args, chat_id);