Replase td_api::shareUserWithBot with td_api::shareUsersWithBot.

This commit is contained in:
levlam 2023-12-22 18:47:23 +03:00
parent 590b3f3c25
commit 66c6e706ab
10 changed files with 73 additions and 40 deletions

View File

@ -7574,13 +7574,13 @@ 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; getLoginUrl chat_id:int53 message_id:int53 button_id:int53 allow_write_access:Bool = HttpUrl;
//@description Shares a user after pressing a keyboardButtonTypeRequestUsers button with the bot //@description Shares users after pressing a keyboardButtonTypeRequestUsers button with the bot
//@chat_id Identifier of the chat with the bot //@chat_id Identifier of the chat with the bot
//@message_id Identifier of the message with the button //@message_id Identifier of the message with the button
//@button_id Identifier of the button //@button_id Identifier of the button
//@shared_user_id Identifier of the shared user //@shared_user_ids Identifiers of the shared users
//@only_check Pass true to check that the user can be shared by the button instead of actually sharing them //@only_check Pass true to check that the users can be shared by the button instead of actually sharing them
shareUserWithBot chat_id:int53 message_id:int53 button_id:int32 shared_user_id:int53 only_check:Bool = Ok; shareUsersWithBot chat_id:int53 message_id:int53 button_id:int32 shared_user_ids:vector<int53> only_check:Bool = Ok;
//@description Shares a chat after pressing a keyboardButtonTypeRequestChat button with the bot //@description Shares a chat after pressing a keyboardButtonTypeRequestChat button with the bot
//@chat_id Identifier of the chat with the bot //@chat_id Identifier of the chat with the bot

View File

@ -4028,18 +4028,20 @@ class SendBotRequestedPeerQuery final : public Td::ResultHandler {
explicit SendBotRequestedPeerQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) { explicit SendBotRequestedPeerQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
} }
void send(MessageFullId message_full_id, int32 button_id, DialogId requested_dialog_id) { void send(MessageFullId message_full_id, int32 button_id, vector<DialogId> &&requested_dialog_ids) {
auto dialog_id = message_full_id.get_dialog_id(); auto dialog_id = message_full_id.get_dialog_id();
auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write); auto input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
if (input_peer == nullptr) { if (input_peer == nullptr) {
return on_error(Status::Error(400, "Can't access the chat")); return on_error(Status::Error(400, "Can't access the chat"));
} }
auto requested_peer = td_->messages_manager_->get_input_peer(requested_dialog_id, AccessRights::Read);
if (requested_peer == nullptr) {
return on_error(Status::Error(400, "Can't access the chosen chat"));
}
vector<telegram_api::object_ptr<telegram_api::InputPeer>> requested_peers; vector<telegram_api::object_ptr<telegram_api::InputPeer>> requested_peers;
requested_peers.push_back(std::move(requested_peer)); for (auto requested_dialog_id : requested_dialog_ids) {
auto requested_peer = td_->messages_manager_->get_input_peer(requested_dialog_id, AccessRights::Read);
if (requested_peer == nullptr) {
return on_error(Status::Error(400, "Can't access the chosen chat"));
}
requested_peers.push_back(std::move(requested_peer));
}
send_query(G()->net_query_creator().create( send_query(G()->net_query_creator().create(
telegram_api::messages_sendBotRequestedPeer(std::move(input_peer), telegram_api::messages_sendBotRequestedPeer(std::move(input_peer),
@ -28616,8 +28618,9 @@ void MessagesManager::do_send_screenshot_taken_notification_message(DialogId dia
->send(dialog_id, random_id); ->send(dialog_id, random_id);
} }
void MessagesManager::share_dialog_with_bot(MessageFullId message_full_id, int32 button_id, DialogId shared_dialog_id, void MessagesManager::share_dialogs_with_bot(MessageFullId message_full_id, int32 button_id,
bool expect_user, bool only_check, Promise<Unit> &&promise) { vector<DialogId> shared_dialog_ids, bool expect_user, bool only_check,
Promise<Unit> &&promise) {
const Message *m = get_message_force(message_full_id, "share_dialog_with_bot"); const Message *m = get_message_force(message_full_id, "share_dialog_with_bot");
if (m == nullptr) { if (m == nullptr) {
return promise.set_error(Status::Error(400, "Message not found")); return promise.set_error(Status::Error(400, "Message not found"));
@ -28626,26 +28629,29 @@ void MessagesManager::share_dialog_with_bot(MessageFullId message_full_id, int32
return promise.set_error(Status::Error(400, "Message has no buttons")); return promise.set_error(Status::Error(400, "Message has no buttons"));
} }
CHECK(m->message_id.is_valid() && m->message_id.is_server()); CHECK(m->message_id.is_valid() && m->message_id.is_server());
if (shared_dialog_id.get_type() != DialogType::User) { TRY_STATUS_PROMISE(promise, m->reply_markup->check_shared_dialog_count(button_id, shared_dialog_ids.size()));
if (!have_dialog_force(shared_dialog_id, "share_dialog_with_bot")) { for (auto shared_dialog_id : shared_dialog_ids) {
return promise.set_error(Status::Error(400, "Shared chat not found")); if (shared_dialog_id.get_type() != DialogType::User) {
} if (!have_dialog_force(shared_dialog_id, "share_dialogs_with_bot")) {
} else { return promise.set_error(Status::Error(400, "Shared chat not found"));
if (!expect_user) { }
return promise.set_error(Status::Error(400, "Wrong chat type")); } else {
} if (!expect_user) {
if (!td_->contacts_manager_->have_user(shared_dialog_id.get_user_id())) { return promise.set_error(Status::Error(400, "Wrong chat type"));
return promise.set_error(Status::Error(400, "Shared user not found")); }
if (!td_->contacts_manager_->have_user(shared_dialog_id.get_user_id())) {
return promise.set_error(Status::Error(400, "Shared user not found"));
}
} }
TRY_STATUS_PROMISE(promise, m->reply_markup->check_shared_dialog(td_, button_id, shared_dialog_id));
} }
TRY_STATUS_PROMISE(promise, m->reply_markup->check_shared_dialog(td_, button_id, shared_dialog_id));
if (only_check) { if (only_check) {
return promise.set_value(Unit()); return promise.set_value(Unit());
} }
td_->create_handler<SendBotRequestedPeerQuery>(std::move(promise)) td_->create_handler<SendBotRequestedPeerQuery>(std::move(promise))
->send(message_full_id, button_id, shared_dialog_id); ->send(message_full_id, button_id, std::move(shared_dialog_ids));
} }
Result<MessageId> MessagesManager::add_local_message( Result<MessageId> MessagesManager::add_local_message(

View File

@ -479,8 +479,8 @@ class MessagesManager final : public Actor {
void set_dialog_message_ttl(DialogId dialog_id, int32 ttl, Promise<Unit> &&promise); void set_dialog_message_ttl(DialogId dialog_id, int32 ttl, Promise<Unit> &&promise);
void share_dialog_with_bot(MessageFullId message_full_id, int32 button_id, DialogId shared_dialog_id, void share_dialogs_with_bot(MessageFullId message_full_id, int32 button_id, vector<DialogId> shared_dialog_ids,
bool expect_user, bool only_check, Promise<Unit> &&promise); bool expect_user, bool only_check, Promise<Unit> &&promise);
Result<MessageId> add_local_message( Result<MessageId> add_local_message(
DialogId dialog_id, td_api::object_ptr<td_api::MessageSender> &&sender, DialogId dialog_id, td_api::object_ptr<td_api::MessageSender> &&sender,

View File

@ -1149,6 +1149,17 @@ Status ReplyMarkup::check_shared_dialog(Td *td, int32 button_id, DialogId dialog
return Status::Error(400, "Button not found"); return Status::Error(400, "Button not found");
} }
Status ReplyMarkup::check_shared_dialog_count(int32 button_id, size_t count) const {
for (auto &row : keyboard) {
for (auto &button : row) {
if (button.requested_dialog_type != nullptr && button.requested_dialog_type->get_button_id() == button_id) {
return button.requested_dialog_type->check_shared_dialog_count(count);
}
}
}
return Status::Error(400, "Button not found");
}
tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup(ContactsManager *contacts_manager, tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup(ContactsManager *contacts_manager,
const unique_ptr<ReplyMarkup> &reply_markup) { const unique_ptr<ReplyMarkup> &reply_markup) {
if (reply_markup == nullptr) { if (reply_markup == nullptr) {

View File

@ -91,6 +91,8 @@ struct ReplyMarkup {
tl_object_ptr<td_api::ReplyMarkup> get_reply_markup_object(ContactsManager *contacts_manager) const; tl_object_ptr<td_api::ReplyMarkup> get_reply_markup_object(ContactsManager *contacts_manager) const;
Status check_shared_dialog(Td *td, int32 button_id, DialogId dialog_id) const; Status check_shared_dialog(Td *td, int32 button_id, DialogId dialog_id) const;
Status check_shared_dialog_count(int32 button_id, size_t count) const;
}; };
bool operator==(const ReplyMarkup &lhs, const ReplyMarkup &rhs); bool operator==(const ReplyMarkup &lhs, const ReplyMarkup &rhs);

View File

@ -16,7 +16,7 @@ RequestedDialogType::RequestedDialogType(td_api::object_ptr<td_api::keyboardButt
CHECK(request_users != nullptr); CHECK(request_users != nullptr);
type_ = Type::User; type_ = Type::User;
button_id_ = request_users->id_; button_id_ = request_users->id_;
max_quantity_ = request_users->max_quantity_; max_quantity_ = max(request_users->max_quantity_, 1);
restrict_is_bot_ = request_users->restrict_user_is_bot_; restrict_is_bot_ = request_users->restrict_user_is_bot_;
is_bot_ = request_users->user_is_bot_; is_bot_ = request_users->user_is_bot_;
restrict_is_premium_ = request_users->restrict_user_is_premium_; restrict_is_premium_ = request_users->restrict_user_is_premium_;
@ -44,7 +44,7 @@ RequestedDialogType::RequestedDialogType(telegram_api::object_ptr<telegram_api::
int32 button_id, int32 max_quantity) { int32 button_id, int32 max_quantity) {
CHECK(peer_type != nullptr); CHECK(peer_type != nullptr);
button_id_ = button_id; button_id_ = button_id;
max_quantity_ = max_quantity; max_quantity_ = max(max_quantity, 1);
switch (peer_type->get_id()) { switch (peer_type->get_id()) {
case telegram_api::requestPeerTypeUser::ID: { case telegram_api::requestPeerTypeUser::ID: {
auto type = telegram_api::move_object_as<telegram_api::requestPeerTypeUser>(peer_type); auto type = telegram_api::move_object_as<telegram_api::requestPeerTypeUser>(peer_type);
@ -273,4 +273,14 @@ Status RequestedDialogType::check_shared_dialog(Td *td, DialogId dialog_id) cons
return Status::OK(); return Status::OK();
} }
Status RequestedDialogType::check_shared_dialog_count(size_t count) const {
if (count == 0) {
return Status::Error(400, "Too few chats are chosen");
}
if (count > static_cast<size_t>(max_quantity_)) {
return Status::Error(400, "Too many chats are chosen");
}
return Status::OK();
}
} // namespace td } // namespace td

View File

@ -59,6 +59,8 @@ class RequestedDialogType {
Status check_shared_dialog(Td *td, DialogId dialog_id) const; Status check_shared_dialog(Td *td, DialogId dialog_id) const;
Status check_shared_dialog_count(size_t count) const;
template <class StorerT> template <class StorerT>
void store(StorerT &storer) const; void store(StorerT &storer) const;

View File

@ -8388,20 +8388,22 @@ void Td::on_request(uint64 id, const td_api::getLoginUrl &request) {
request.allow_write_access_, std::move(promise)); request.allow_write_access_, std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::shareUserWithBot &request) { void Td::on_request(uint64 id, const td_api::shareUsersWithBot &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
messages_manager_->share_dialog_with_bot({DialogId(request.chat_id_), MessageId(request.message_id_)}, auto user_ids = UserId::get_user_ids(request.shared_user_ids_);
request.button_id_, DialogId(UserId(request.shared_user_id_)), true, auto dialog_ids = transform(user_ids, [](UserId user_id) { return DialogId(user_id); });
request.only_check_, std::move(promise)); messages_manager_->share_dialogs_with_bot({DialogId(request.chat_id_), MessageId(request.message_id_)},
request.button_id_, std::move(dialog_ids), true, request.only_check_,
std::move(promise));
} }
void Td::on_request(uint64 id, const td_api::shareChatWithBot &request) { void Td::on_request(uint64 id, const td_api::shareChatWithBot &request) {
CHECK_IS_USER(); CHECK_IS_USER();
CREATE_OK_REQUEST_PROMISE(); CREATE_OK_REQUEST_PROMISE();
messages_manager_->share_dialog_with_bot({DialogId(request.chat_id_), MessageId(request.message_id_)}, messages_manager_->share_dialogs_with_bot({DialogId(request.chat_id_), MessageId(request.message_id_)},
request.button_id_, DialogId(request.shared_chat_id_), false, request.button_id_, {DialogId(request.shared_chat_id_)}, false,
request.only_check_, std::move(promise)); request.only_check_, std::move(promise));
} }
void Td::on_request(uint64 id, td_api::getInlineQueryResults &request) { void Td::on_request(uint64 id, td_api::getInlineQueryResults &request) {

View File

@ -1509,7 +1509,7 @@ class Td final : public Actor {
void on_request(uint64 id, const td_api::getLoginUrl &request); void on_request(uint64 id, const td_api::getLoginUrl &request);
void on_request(uint64 id, const td_api::shareUserWithBot &request); void on_request(uint64 id, const td_api::shareUsersWithBot &request);
void on_request(uint64 id, const td_api::shareChatWithBot &request); void on_request(uint64 id, const td_api::shareChatWithBot &request);

View File

@ -6095,10 +6095,10 @@ class CliClient final : public Actor {
ChatId chat_id; ChatId chat_id;
MessageId message_id; MessageId message_id;
int32 button_id; int32 button_id;
UserId shared_user_id; string shared_user_ids;
get_args(args, chat_id, message_id, button_id, shared_user_id); get_args(args, chat_id, message_id, button_id, shared_user_ids);
send_request( send_request(td_api::make_object<td_api::shareUsersWithBot>(chat_id, message_id, button_id,
td_api::make_object<td_api::shareUserWithBot>(chat_id, message_id, button_id, shared_user_id, op == "suwbc")); as_user_ids(shared_user_ids), op == "suwbc"));
} else if (op == "scwb" || op == "scwbc") { } else if (op == "scwb" || op == "scwbc") {
ChatId chat_id; ChatId chat_id;
MessageId message_id; MessageId message_id;