diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 1bfc45f23..6bad8796f 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -473,7 +473,7 @@ user id:int53 first_name:string last_name:string username:string phone_number:st //@share_text The text that is shown on the bot's profile page and is sent together with the link when users share the bot //@param_description The text shown in the chat with the bot if the chat is empty //@commands List of the bot commands -//@default_group_administrator_rights Default administrator rights for adding the bot to basic groups and supergroups; may be null +//@default_group_administrator_rights Default administrator rights for adding the bot to basic group and supergroup chats; may be null //@default_channel_administrator_rights Default administrator rights for adding the bot to channels; may be null botInfo share_text:string description:string commands:vector default_group_administrator_rights:chatAdministratorRights default_channel_administrator_rights:chatAdministratorRights = BotInfo; @@ -790,7 +790,7 @@ messageReplyInfo reply_count:int32 recent_replier_ids:vector last //@reaction Text representation of the reaction //@total_count Number of times the reaction was added //@is_chosen True, if the reaction is chosen by the current user -//@recent_sender_ids Identifiers of at most 3 recent message senders, added the reaction; available in private chats, basic groups and supergroups +//@recent_sender_ids Identifiers of at most 3 recent message senders, added the reaction; available in private, basic group and supergroup chats messageReaction reaction:string total_count:int32 is_chosen:Bool recent_sender_ids:vector = MessageReaction; //@description Contains information about interactions with a message @@ -912,10 +912,10 @@ foundFileDownloads total_counts:downloadedFileCounts files:vector //@description Notification settings applied to all private and secret chats when the corresponding chat setting has a default value notificationSettingsScopePrivateChats = NotificationSettingsScope; -//@description Notification settings applied to all basic groups and supergroups when the corresponding chat setting has a default value +//@description Notification settings applied to all basic group and supergroup chats when the corresponding chat setting has a default value notificationSettingsScopeGroupChats = NotificationSettingsScope; -//@description Notification settings applied to all channels when the corresponding chat setting has a default value +//@description Notification settings applied to all channel chats when the corresponding chat setting has a default value notificationSettingsScopeChannelChats = NotificationSettingsScope; @@ -5712,6 +5712,12 @@ deleteCommands scope:BotCommandScope language_code:string = Ok; //@language_code A two-letter ISO 639-1 language code or an empty string getCommands scope:BotCommandScope language_code:string = BotCommands; +//@description Sets default administrator rights for adding the bot to basic group and supergroup chats; for bots only @default_group_administrator_rights Default administrator rights for adding the bot to basic group and supergroup chats; may be null +setDefaultGroupAdministratorRights default_group_administrator_rights:chatAdministratorRights = Ok; + +//@description Sets default administrator rights for adding the bot to channel chats; for bots only @default_channel_administrator_rights Default administrator rights for adding the bot to channels; may be null +setDefaultChannelAdministratorRights default_channel_administrator_rights:chatAdministratorRights = Ok; + //@description Returns all active sessions of the current user getActiveSessions = Sessions; diff --git a/td/telegram/Account.cpp b/td/telegram/Account.cpp index f93f43f20..54452c375 100644 --- a/td/telegram/Account.cpp +++ b/td/telegram/Account.cpp @@ -393,6 +393,62 @@ class ResetWebAuthorizationsQuery final : public Td::ResultHandler { } }; +class SetBotGroupDefaultAdminRightsQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit SetBotGroupDefaultAdminRightsQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(AdministratorRights administrator_rights) { + send_query(G()->net_query_creator().create( + telegram_api::bots_setBotGroupDefaultAdminRights(administrator_rights.get_chat_admin_rights()))); + } + + 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()); + } + + bool result = result_ptr.move_as_ok(); + LOG_IF(WARNING, !result) << "Failed to set group default administrator rights"; + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + +class SetBotBroadcastDefaultAdminRightsQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit SetBotBroadcastDefaultAdminRightsQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(AdministratorRights administrator_rights) { + send_query(G()->net_query_creator().create( + telegram_api::bots_setBotBroadcastDefaultAdminRights(administrator_rights.get_chat_admin_rights()))); + } + + 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()); + } + + bool result = result_ptr.move_as_ok(); + LOG_IF(WARNING, !result) << "Failed to set channel default administrator rights"; + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + void set_account_ttl(Td *td, int32 account_ttl, Promise &&promise) { td->create_handler(std::move(promise))->send(account_ttl); } @@ -453,4 +509,13 @@ void disconnect_all_websites(Td *td, Promise &&promise) { td->create_handler(std::move(promise))->send(); } +void set_default_group_administrator_rights(Td *td, AdministratorRights administrator_rights, Promise &&promise) { + td->create_handler(std::move(promise))->send(administrator_rights); +} + +void set_default_channel_administrator_rights(Td *td, AdministratorRights administrator_rights, + Promise &&promise) { + td->create_handler(std::move(promise))->send(administrator_rights); +} + } // namespace td diff --git a/td/telegram/Account.h b/td/telegram/Account.h index 943d20218..3864c8416 100644 --- a/td/telegram/Account.h +++ b/td/telegram/Account.h @@ -6,6 +6,7 @@ // #pragma once +#include "td/telegram/DialogParticipant.h" #include "td/telegram/td_api.h" #include "td/actor/PromiseFuture.h" @@ -41,4 +42,9 @@ void disconnect_website(Td *td, int64 website_id, Promise &&promise); void disconnect_all_websites(Td *td, Promise &&promise); +void set_default_group_administrator_rights(Td *td, AdministratorRights administrator_rights, Promise &&promise); + +void set_default_channel_administrator_rights(Td *td, AdministratorRights administrator_rights, + Promise &&promise); + } // namespace td diff --git a/td/telegram/DialogParticipant.cpp b/td/telegram/DialogParticipant.cpp index b5651f157..8d409bf50 100644 --- a/td/telegram/DialogParticipant.cpp +++ b/td/telegram/DialogParticipant.cpp @@ -18,6 +18,20 @@ namespace td { +AdministratorRights::AdministratorRights( + const td_api::object_ptr &administrator_rights) { + if (administrator_rights == nullptr) { + flags_ = 0; + return; + } + *this = AdministratorRights(administrator_rights->is_anonymous_, administrator_rights->can_manage_chat_, + administrator_rights->can_change_info_, administrator_rights->can_post_messages_, + administrator_rights->can_edit_messages_, administrator_rights->can_delete_messages_, + administrator_rights->can_invite_users_, administrator_rights->can_restrict_members_, + administrator_rights->can_pin_messages_, administrator_rights->can_promote_members_, + administrator_rights->can_manage_video_chats_); +} + AdministratorRights::AdministratorRights(bool is_anonymous, bool can_manage_dialog, bool can_change_info, bool can_post_messages, bool can_edit_messages, bool can_delete_messages, bool can_invite_users, bool can_restrict_members, bool can_pin_messages, diff --git a/td/telegram/DialogParticipant.h b/td/telegram/DialogParticipant.h index 5b0879e25..bdf02d928 100644 --- a/td/telegram/DialogParticipant.h +++ b/td/telegram/DialogParticipant.h @@ -50,6 +50,8 @@ class AdministratorRights { AdministratorRights() : flags_(0) { } + explicit AdministratorRights(const td_api::object_ptr &administrator_rights); + AdministratorRights(bool is_anonymous, bool can_manage_dialog, bool can_change_info, bool can_post_messages, bool can_edit_messages, bool can_delete_messages, bool can_invite_users, bool can_restrict_members, bool can_pin_messages, bool can_promote_members, diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index af3b29be0..e9b06d1f0 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -6789,6 +6789,20 @@ void Td::on_request(uint64 id, td_api::getCommands &request) { get_commands(this, std::move(request.scope_), std::move(request.language_code_), std::move(promise)); } +void Td::on_request(uint64 id, const td_api::setDefaultGroupAdministratorRights &request) { + CHECK_IS_BOT(); + CREATE_OK_REQUEST_PROMISE(); + set_default_group_administrator_rights(this, AdministratorRights(request.default_group_administrator_rights_), + std::move(promise)); +} + +void Td::on_request(uint64 id, const td_api::setDefaultChannelAdministratorRights &request) { + CHECK_IS_BOT(); + CREATE_OK_REQUEST_PROMISE(); + set_default_channel_administrator_rights(this, AdministratorRights(request.default_channel_administrator_rights_), + std::move(promise)); +} + void Td::on_request(uint64 id, const td_api::setLocation &request) { CHECK_IS_USER(); CREATE_OK_REQUEST_PROMISE(); diff --git a/td/telegram/Td.h b/td/telegram/Td.h index 0c5edf876..c0da4721d 100644 --- a/td/telegram/Td.h +++ b/td/telegram/Td.h @@ -999,6 +999,10 @@ class Td final : public Actor { void on_request(uint64 id, td_api::getCommands &request); + void on_request(uint64 id, const td_api::setDefaultGroupAdministratorRights &request); + + void on_request(uint64 id, const td_api::setDefaultChannelAdministratorRights &request); + void on_request(uint64 id, const td_api::setLocation &request); void on_request(uint64 id, td_api::setProfilePhoto &request);