diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index fd3933ff1..f8421b48c 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -685,7 +685,7 @@ basicGroupFullInfo photo:chatPhoto description:string creator_user_id:int53 memb //@has_location True, if the supergroup is connected to a location, i.e. the supergroup is a location-based supergroup //@sign_messages True, if messages sent to the channel need to contain information about the sender. This field is only applicable to channels //@join_to_send_messages True, if users need to join the supergroup before they can send messages. Always true for channels and non-discussion supergroups -//@join_by_request True, if all users directly joining the chat need to be approved by chat administrators. Always false for channels and supergroups without username, location or a linked chat +//@join_by_request True, if all users directly joining the supergroup need to be approved by supergroup administrators. Always false for channels and supergroups without username, location or a linked chat //@is_slow_mode_enabled True, if the slow mode is enabled in the supergroup //@is_channel True, if the supergroup is a channel //@is_broadcast_group True, if the supergroup is a broadcast group, i.e. only administrators can send messages and there is no limit on the number of members @@ -5873,6 +5873,12 @@ setSupergroupStickerSet supergroup_id:int53 sticker_set_id:int64 = Ok; //@description Toggles whether sender signature is added to sent messages in a channel; requires can_change_info administrator right @supergroup_id Identifier of the channel @sign_messages New value of sign_messages toggleSupergroupSignMessages supergroup_id:int53 sign_messages:Bool = Ok; +//@description Toggles whether joining is mandatory to send messages to a discussion supergroup; requires can_restrict_members administrator right @supergroup_id Identifier of the supergroup @join_to_send_messages New value of join_to_send_messages +toggleSupergroupJoinToSendMessages supergroup_id:int53 join_to_send_messages:Bool = Ok; + +//@description Toggles whether all users directly joining the supergroup need to be approved by supergroup administrators; requires can_restrict_members administrator right @supergroup_id Identifier of the channel @join_by_request New value of join_by_request +toggleSupergroupJoinByRequest supergroup_id:int53 join_by_request: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:int53 is_all_history_available:Bool = Ok; diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index af077760e..ea10e9a84 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -844,6 +844,86 @@ class ToggleChannelSignaturesQuery final : public Td::ResultHandler { } }; +class ToggleChannelJoinToSendQuery final : public Td::ResultHandler { + Promise promise_; + ChannelId channel_id_; + + public: + explicit ToggleChannelJoinToSendQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(ChannelId channel_id, bool join_to_send) { + 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_toggleJoinToSend(std::move(input_channel), join_to_send))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto ptr = result_ptr.move_as_ok(); + LOG(INFO) << "Receive result for ToggleChannelJoinToSendQuery: " << to_string(ptr); + td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); + } + + void on_error(Status status) final { + if (status.message() == "CHAT_NOT_MODIFIED") { + if (!td_->auth_manager_->is_bot()) { + promise_.set_value(Unit()); + return; + } + } else { + td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ToggleChannelJoinToSendQuery"); + } + promise_.set_error(std::move(status)); + } +}; + +class ToggleChannelJoinRequestQuery final : public Td::ResultHandler { + Promise promise_; + ChannelId channel_id_; + + public: + explicit ToggleChannelJoinRequestQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(ChannelId channel_id, bool join_request) { + 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_toggleJoinRequest(std::move(input_channel), join_request))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + auto ptr = result_ptr.move_as_ok(); + LOG(INFO) << "Receive result for ToggleChannelJoinRequestQuery: " << to_string(ptr); + td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_)); + } + + void on_error(Status status) final { + if (status.message() == "CHAT_NOT_MODIFIED") { + if (!td_->auth_manager_->is_bot()) { + promise_.set_value(Unit()); + return; + } + } else { + td_->contacts_manager_->on_get_channel_error(channel_id_, status, "ToggleChannelJoinRequestQuery"); + } + promise_.set_error(std::move(status)); + } +}; + class TogglePrehistoryHiddenQuery final : public Td::ResultHandler { Promise promise_; ChannelId channel_id_; @@ -6509,6 +6589,36 @@ void ContactsManager::toggle_channel_sign_messages(ChannelId channel_id, bool si td_->create_handler(std::move(promise))->send(channel_id, sign_messages); } +void ContactsManager::toggle_channel_join_to_send(ChannelId channel_id, bool join_to_send, Promise &&promise) { + auto c = get_channel(channel_id); + if (c == nullptr) { + return promise.set_error(Status::Error(400, "Supergroup not found")); + } + if (get_channel_type(c) == ChannelType::Broadcast) { + return promise.set_error(Status::Error(400, "The method can't be called for channels")); + } + if (!get_channel_permissions(c).can_restrict_members()) { + return promise.set_error(Status::Error(400, "Not enough rights")); + } + + td_->create_handler(std::move(promise))->send(channel_id, join_to_send); +} + +void ContactsManager::toggle_channel_join_request(ChannelId channel_id, bool join_request, Promise &&promise) { + auto c = get_channel(channel_id); + if (c == nullptr) { + return promise.set_error(Status::Error(400, "Supergroup not found")); + } + if (get_channel_type(c) == ChannelType::Broadcast) { + return promise.set_error(Status::Error(400, "The method can't be called for channels")); + } + if (!get_channel_permissions(c).can_restrict_members()) { + return promise.set_error(Status::Error(400, "Not enough rights")); + } + + td_->create_handler(std::move(promise))->send(channel_id, join_request); +} + void ContactsManager::toggle_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available, Promise &&promise) { auto c = get_channel(channel_id); diff --git a/td/telegram/ContactsManager.h b/td/telegram/ContactsManager.h index 803c996df..c82ef990c 100644 --- a/td/telegram/ContactsManager.h +++ b/td/telegram/ContactsManager.h @@ -347,6 +347,10 @@ class ContactsManager final : public Actor { void toggle_channel_sign_messages(ChannelId channel_id, bool sign_messages, Promise &&promise); + void toggle_channel_join_to_send(ChannelId channel_id, bool joint_to_send, Promise &&promise); + + void toggle_channel_join_request(ChannelId channel_id, bool join_request, Promise &&promise); + void toggle_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available, Promise &&promise); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index c20c817c0..89ddf2e8e 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6868,6 +6868,20 @@ void Td::on_request(uint64 id, const td_api::toggleSupergroupSignMessages &reque std::move(promise)); } +void Td::on_request(uint64 id, const td_api::toggleSupergroupJoinToSendMessages &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + contacts_manager_->toggle_channel_join_to_send(ChannelId(request.supergroup_id_), request.join_to_send_messages_, + std::move(promise)); +} + +void Td::on_request(uint64 id, const td_api::toggleSupergroupJoinByRequest &request) { + CHECK_IS_USER(); + CREATE_OK_REQUEST_PROMISE(); + contacts_manager_->toggle_channel_join_request(ChannelId(request.supergroup_id_), request.join_by_request_, + std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::toggleSupergroupIsAllHistoryAvailable &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index e585eb951..7e2dd0b5c 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -1032,6 +1032,10 @@ class Td final : public Actor { void on_request(uint64 id, const td_api::toggleSupergroupSignMessages &request); + void on_request(uint64 id, const td_api::toggleSupergroupJoinToSendMessages &request); + + void on_request(uint64 id, const td_api::toggleSupergroupJoinByRequest &request); + void on_request(uint64 id, const td_api::toggleSupergroupIsAllHistoryAvailable &request); void on_request(uint64 id, const td_api::toggleSupergroupIsBroadcastGroup &request); diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index b4f4444f1..6fbb8d381 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -4372,6 +4372,18 @@ class CliClient final : public Actor { get_args(args, supergroup_id, sign_messages); send_request( td_api::make_object(as_supergroup_id(supergroup_id), sign_messages)); + } else if (op == "tsgjtsm") { + string supergroup_id; + bool join_to_send_message; + get_args(args, supergroup_id, join_to_send_message); + send_request(td_api::make_object(as_supergroup_id(supergroup_id), + join_to_send_message)); + } else if (op == "tsgjtsm") { + string supergroup_id; + bool join_by_request; + get_args(args, supergroup_id, join_by_request); + send_request( + td_api::make_object(as_supergroup_id(supergroup_id), join_by_request)); } else if (op == "scar") { ChatId chat_id; string available_reactions;