diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index 32fc25c23..5b1239994 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -1725,13 +1725,14 @@ keyboardButtonTypeRequestLocation = KeyboardButtonType; //@description A button that allows the user to create and send a poll when pressed; available only in private chats @force_regular If true, only regular polls must be allowed to create @force_quiz If true, only polls in quiz mode must be allowed to create keyboardButtonTypeRequestPoll force_regular:Bool force_quiz:Bool = KeyboardButtonType; -//@description A button that requests a user to be shared by the current user; available only in private chats. Use the method shareUserWithBot to complete the request +//@description A button that requests users to be shared by the current user; available only in private chats. Use the method shareUsersWithBot to complete the request //@id Unique button identifier -//@restrict_user_is_bot True, if the shared user must or must not be a bot -//@user_is_bot True, if the shared user must be a bot; otherwise, the shared user must no be a bot. Ignored if restrict_user_is_bot is false -//@restrict_user_is_premium True, if the shared user must or must not be a Telegram Premium user -//@user_is_premium True, if the shared user must be a Telegram Premium user; otherwise, the shared user must no be a Telegram Premium user. Ignored if restrict_user_is_premium is false -keyboardButtonTypeRequestUser id:int32 restrict_user_is_bot:Bool user_is_bot:Bool restrict_user_is_premium:Bool user_is_premium:Bool = KeyboardButtonType; +//@restrict_user_is_bot True, if the shared users must or must not be bots +//@user_is_bot True, if the shared users must be bots; otherwise, the shared users must not be bots. Ignored if restrict_user_is_bot is false +//@restrict_user_is_premium True, if the shared users must or must not be Telegram Premium users +//@user_is_premium True, if the shared users must be Telegram Premium users; otherwise, the shared users must not be Telegram Premium users. Ignored if restrict_user_is_premium is false +//@max_quantity The maximum number of users to share +keyboardButtonTypeRequestUsers id:int32 restrict_user_is_bot:Bool user_is_bot:Bool restrict_user_is_premium:Bool user_is_premium:Bool max_quantity:int32 = KeyboardButtonType; //@description A button that requests a chat to be shared by the current user; available only in private chats. Use the method shareChatWithBot to complete the request //@id Unique button identifier @@ -7573,7 +7574,7 @@ getLoginUrlInfo chat_id:int53 message_id:int53 button_id:int53 = LoginUrlInfo; getLoginUrl chat_id:int53 message_id:int53 button_id:int53 allow_write_access:Bool = HttpUrl; -//@description Shares a user after pressing a keyboardButtonTypeRequestUser button with the bot +//@description Shares a user after pressing a keyboardButtonTypeRequestUsers button with the bot //@chat_id Identifier of the chat with the bot //@message_id Identifier of the message with the button //@button_id Identifier of the button diff --git a/td/telegram/ReplyMarkup.cpp b/td/telegram/ReplyMarkup.cpp index 870dceb8a..620c3a30b 100644 --- a/td/telegram/ReplyMarkup.cpp +++ b/td/telegram/ReplyMarkup.cpp @@ -244,8 +244,8 @@ static KeyboardButton get_keyboard_button(tl_object_ptr(keyboard_button_ptr); button.type = KeyboardButton::Type::RequestDialog; button.text = std::move(keyboard_button->text_); - button.requested_dialog_type = - td::make_unique(std::move(keyboard_button->peer_type_), keyboard_button->button_id_); + button.requested_dialog_type = td::make_unique( + std::move(keyboard_button->peer_type_), keyboard_button->button_id_, keyboard_button->max_quantity_); break; } default: @@ -525,11 +525,11 @@ static Result get_keyboard_button(tl_object_ptrurl_); break; } - case td_api::keyboardButtonTypeRequestUser::ID: { + case td_api::keyboardButtonTypeRequestUsers::ID: { if (!request_buttons_allowed) { return Status::Error(400, "Users can be requested in private chats only"); } - auto button_type = move_tl_object_as(button->type_); + auto button_type = move_tl_object_as(button->type_); current_button.type = KeyboardButton::Type::RequestDialog; current_button.requested_dialog_type = td::make_unique(std::move(button_type)); break; @@ -865,9 +865,11 @@ static tl_object_ptr get_input_keyboard_button(con case KeyboardButton::Type::WebView: return make_tl_object(keyboard_button.text, keyboard_button.url); case KeyboardButton::Type::RequestDialog: + CHECK(keyboard_button.requested_dialog_type != nullptr); return make_tl_object( keyboard_button.text, keyboard_button.requested_dialog_type->get_button_id(), - keyboard_button.requested_dialog_type->get_input_request_peer_type_object(), 1); + keyboard_button.requested_dialog_type->get_input_request_peer_type_object(), + keyboard_button.requested_dialog_type->get_max_quantity()); default: UNREACHABLE(); return nullptr; diff --git a/td/telegram/RequestedDialogType.cpp b/td/telegram/RequestedDialogType.cpp index 1de9f11df..358d95b1b 100644 --- a/td/telegram/RequestedDialogType.cpp +++ b/td/telegram/RequestedDialogType.cpp @@ -12,14 +12,15 @@ namespace td { -RequestedDialogType::RequestedDialogType(td_api::object_ptr &&request_user) { - CHECK(request_user != nullptr); +RequestedDialogType::RequestedDialogType(td_api::object_ptr &&request_users) { + CHECK(request_users != nullptr); type_ = Type::User; - button_id_ = request_user->id_; - restrict_is_bot_ = request_user->restrict_user_is_bot_; - is_bot_ = request_user->user_is_bot_; - restrict_is_premium_ = request_user->restrict_user_is_premium_; - is_premium_ = request_user->user_is_premium_; + button_id_ = request_users->id_; + max_quantity_ = request_users->max_quantity_; + restrict_is_bot_ = request_users->restrict_user_is_bot_; + is_bot_ = request_users->user_is_bot_; + restrict_is_premium_ = request_users->restrict_user_is_premium_; + is_premium_ = request_users->user_is_premium_; } RequestedDialogType::RequestedDialogType(td_api::object_ptr &&request_dialog) { @@ -40,9 +41,10 @@ RequestedDialogType::RequestedDialogType(td_api::object_ptr &&peer_type, - int32 button_id) { + int32 button_id, int32 max_quantity) { CHECK(peer_type != nullptr); button_id_ = button_id; + max_quantity_ = max_quantity; switch (peer_type->get_id()) { case telegram_api::requestPeerTypeUser::ID: { auto type = telegram_api::move_object_as(peer_type); @@ -87,8 +89,8 @@ RequestedDialogType::RequestedDialogType(telegram_api::object_ptr RequestedDialogType::get_keyboard_button_type_object() const { if (type_ == Type::User) { - return td_api::make_object(button_id_, restrict_is_bot_, is_bot_, - restrict_is_premium_, is_premium_); + return td_api::make_object( + button_id_, restrict_is_bot_, is_bot_, restrict_is_premium_, is_premium_, max_quantity_); } else { auto user_administrator_rights = restrict_user_administrator_rights_ ? user_administrator_rights_.get_chat_administrator_rights_object() @@ -173,6 +175,10 @@ int32 RequestedDialogType::get_button_id() const { return button_id_; } +int32 RequestedDialogType::get_max_quantity() const { + return max_quantity_; +} + Status RequestedDialogType::check_shared_dialog(Td *td, DialogId dialog_id) const { switch (dialog_id.get_type()) { case DialogType::User: { diff --git a/td/telegram/RequestedDialogType.h b/td/telegram/RequestedDialogType.h index 989598c73..5ad1ca703 100644 --- a/td/telegram/RequestedDialogType.h +++ b/td/telegram/RequestedDialogType.h @@ -22,6 +22,7 @@ class RequestedDialogType { enum class Type : int32 { User, Group, Channel }; Type type_ = Type::User; int32 button_id_ = 0; + int32 max_quantity_ = 1; // User only bool restrict_is_bot_ = false; // User only bool is_bot_ = false; // User only bool restrict_is_premium_ = false; // User only @@ -41,11 +42,12 @@ class RequestedDialogType { public: RequestedDialogType() = default; - explicit RequestedDialogType(td_api::object_ptr &&request_user); + explicit RequestedDialogType(td_api::object_ptr &&request_users); explicit RequestedDialogType(td_api::object_ptr &&request_dialog); - explicit RequestedDialogType(telegram_api::object_ptr &&peer_type, int32 button_id); + explicit RequestedDialogType(telegram_api::object_ptr &&peer_type, int32 button_id, + int32 max_quantity); td_api::object_ptr get_keyboard_button_type_object() const; @@ -53,6 +55,8 @@ class RequestedDialogType { int32 get_button_id() const; + int32 get_max_quantity() const; + Status check_shared_dialog(Td *td, DialogId dialog_id) const; template diff --git a/td/telegram/RequestedDialogType.hpp b/td/telegram/RequestedDialogType.hpp index 62f7789c8..dd584b166 100644 --- a/td/telegram/RequestedDialogType.hpp +++ b/td/telegram/RequestedDialogType.hpp @@ -14,6 +14,7 @@ namespace td { template void RequestedDialogType::store(StorerT &storer) const { + bool has_max_quantity = max_quantity_ != 1; BEGIN_STORE_FLAGS(); STORE_FLAG(restrict_is_bot_); STORE_FLAG(is_bot_); @@ -27,6 +28,7 @@ void RequestedDialogType::store(StorerT &storer) const { STORE_FLAG(is_created_); STORE_FLAG(restrict_user_administrator_rights_); STORE_FLAG(restrict_bot_administrator_rights_); + STORE_FLAG(has_max_quantity); END_STORE_FLAGS(); td::store(type_, storer); td::store(button_id_, storer); @@ -36,10 +38,14 @@ void RequestedDialogType::store(StorerT &storer) const { if (restrict_bot_administrator_rights_) { td::store(bot_administrator_rights_, storer); } + if (has_max_quantity) { + td::store(max_quantity_, storer); + } } template void RequestedDialogType::parse(ParserT &parser) { + bool has_max_quantity; BEGIN_PARSE_FLAGS(); PARSE_FLAG(restrict_is_bot_); PARSE_FLAG(is_bot_); @@ -53,6 +59,7 @@ void RequestedDialogType::parse(ParserT &parser) { PARSE_FLAG(is_created_); PARSE_FLAG(restrict_user_administrator_rights_); PARSE_FLAG(restrict_bot_administrator_rights_); + PARSE_FLAG(has_max_quantity); END_PARSE_FLAGS(); td::parse(type_, parser); td::parse(button_id_, parser); @@ -62,6 +69,11 @@ void RequestedDialogType::parse(ParserT &parser) { if (restrict_bot_administrator_rights_) { td::parse(bot_administrator_rights_, parser); } + if (has_max_quantity) { + td::parse(max_quantity_, parser); + } else { + max_quantity_ = 1; + } } } // namespace td