diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index aa77b88ec..9dfec93d9 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -4779,6 +4779,9 @@ toggleSupergroupSignMessages supergroup_id:int32 sign_messages:Bool = Ok; //@description Toggles whether the message history of a supergroup is available to new members; requires can_change_info administrator right @supergroup_id The identifier of the supergroup @is_all_history_available The new value of is_all_history_available toggleSupergroupIsAllHistoryAvailable supergroup_id:int32 is_all_history_available:Bool = Ok; +//@description Upgrades supergroup to a broadcast group; requires owner privileges in the supergroup @supergroup_id Identifier of the supergroup +toggleSupergroupIsBroadcastGroup supergroup_id:int32 = Ok; + //@description Reports some messages from a user in a supergroup as spam; requires administrator rights in the supergroup @supergroup_id Supergroup identifier @user_id User identifier @message_ids Identifiers of messages sent in the supergroup by the user. This list must be non-empty reportSupergroupSpam supergroup_id:int32 user_id:int32 message_ids:vector = Ok; diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index 981fc6f52..2fbe17949 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index 969a47935..8e5e4f89b 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -1208,6 +1208,45 @@ class TogglePrehistoryHiddenQuery : public Td::ResultHandler { } }; +class ConvertToGigagroupQuery : public Td::ResultHandler { + Promise promise_; + ChannelId channel_id_; + + public: + explicit ConvertToGigagroupQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(ChannelId channel_id) { + channel_id_ = channel_id; + + auto input_channel = td->contacts_manager_->get_input_channel(channel_id); + CHECK(input_channel != nullptr); + send_query(G()->net_query_creator().create(telegram_api::channels_convertToGigagroup(std::move(input_channel)))); + } + + void on_result(uint64 id, BufferSlice packet) override { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(id, result_ptr.move_as_error()); + } + + auto ptr = result_ptr.move_as_ok(); + LOG(INFO) << "Receive result for ConvertToGigagroupQuery: " << to_string(ptr); + + td->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); + } + + void on_error(uint64 id, Status status) override { + if (status.message() == "CHAT_NOT_MODIFIED") { + promise_.set_value(Unit()); + return; + } else { + td->contacts_manager_->on_get_channel_error(channel_id_, status, "ConvertToGigagroupQuery"); + } + promise_.set_error(std::move(status)); + } +}; + class EditChatAboutQuery : public Td::ResultHandler { Promise promise_; DialogId dialog_id_; @@ -6159,6 +6198,21 @@ void ContactsManager::toggle_channel_is_all_history_available(ChannelId channel_ td_->create_handler(std::move(promise))->send(channel_id, is_all_history_available); } +void ContactsManager::convert_channel_to_gigagroup(ChannelId channel_id, Promise &&promise) { + auto c = get_channel(channel_id); + if (c == nullptr) { + return promise.set_error(Status::Error(6, "Supergroup not found")); + } + if (!get_channel_permissions(c).is_creator()) { + return promise.set_error(Status::Error(6, "Not enough rights to convert group to broadcast group")); + } + if (get_channel_type(c) != ChannelType::Megagroup) { + return promise.set_error(Status::Error(6, "Chat must be a supergroup")); + } + + td_->create_handler(std::move(promise))->send(channel_id); +} + void ContactsManager::set_channel_description(ChannelId channel_id, const string &description, Promise &&promise) { auto new_description = strip_empty_characters(description, MAX_DESCRIPTION_LENGTH); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 05b87c1c9..f903248b4 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -352,6 +352,8 @@ class ContactsManager : public Actor { void toggle_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available, Promise &&promise); + void convert_channel_to_gigagroup(ChannelId channel_id, Promise &&promise); + void set_channel_description(ChannelId channel_id, const string &description, Promise &&promise); void set_channel_discussion_group(DialogId dialog_id, DialogId discussion_dialog_id, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 2920a1869..1f2131314 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6733,6 +6733,12 @@ void Td::on_request(uint64 id, const td_api::toggleSupergroupIsAllHistoryAvailab request.is_all_history_available_, std::move(promise)); } +void Td::on_request(uint64 id, const td_api::toggleSupergroupIsBroadcastGroup &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + contacts_manager_->convert_channel_to_gigagroup(ChannelId(request.supergroup_id_), std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::reportSupergroupSpam &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 625286588..d3672bbac 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -892,6 +892,8 @@ class Td final : public NetQueryCallback { void on_request(uint64 id, const td_api::toggleSupergroupIsAllHistoryAvailable &request); + void on_request(uint64 id, const td_api::toggleSupergroupIsBroadcastGroup &request); + void on_request(uint64 id, const td_api::reportSupergroupSpam &request); void on_request(uint64 id, td_api::getSupergroupMembers &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 02f09b55b..43891ff61 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -3728,6 +3728,10 @@ class CliClient final : public Actor { get_args(args, supergroup_id, is_all_history_available); send_request(td_api::make_object(as_supergroup_id(supergroup_id), is_all_history_available)); + } else if (op == "ToggleSupergroupIsBroadcastGroup") { + string supergroup_id; + get_args(args, supergroup_id); + send_request(td_api::make_object(as_supergroup_id(supergroup_id))); } else if (op == "tsgsm") { string supergroup_id; bool sign_messages;