Replase td_api::shareUserWithBot with td_api::shareUsersWithBot.
This commit is contained in:
parent
590b3f3c25
commit
66c6e706ab
@ -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;
|
||||
|
||||
|
||||
//@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
|
||||
//@message_id Identifier of the message with the button
|
||||
//@button_id Identifier of the button
|
||||
//@shared_user_id Identifier of the shared user
|
||||
//@only_check Pass true to check that the user 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;
|
||||
//@shared_user_ids Identifiers of the shared users
|
||||
//@only_check Pass true to check that the users can be shared by the button instead of actually sharing them
|
||||
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
|
||||
//@chat_id Identifier of the chat with the bot
|
||||
|
@ -4028,18 +4028,20 @@ class SendBotRequestedPeerQuery final : public Td::ResultHandler {
|
||||
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 input_peer = td_->messages_manager_->get_input_peer(dialog_id, AccessRights::Write);
|
||||
if (input_peer == nullptr) {
|
||||
return on_error(Status::Error(400, "Can't access the chat"));
|
||||
}
|
||||
vector<telegram_api::object_ptr<telegram_api::InputPeer>> requested_peers;
|
||||
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"));
|
||||
}
|
||||
vector<telegram_api::object_ptr<telegram_api::InputPeer>> requested_peers;
|
||||
requested_peers.push_back(std::move(requested_peer));
|
||||
}
|
||||
|
||||
send_query(G()->net_query_creator().create(
|
||||
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);
|
||||
}
|
||||
|
||||
void MessagesManager::share_dialog_with_bot(MessageFullId message_full_id, int32 button_id, DialogId shared_dialog_id,
|
||||
bool expect_user, bool only_check, Promise<Unit> &&promise) {
|
||||
void MessagesManager::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) {
|
||||
const Message *m = get_message_force(message_full_id, "share_dialog_with_bot");
|
||||
if (m == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Message not found"));
|
||||
@ -28626,8 +28629,10 @@ void MessagesManager::share_dialog_with_bot(MessageFullId message_full_id, int32
|
||||
return promise.set_error(Status::Error(400, "Message has no buttons"));
|
||||
}
|
||||
CHECK(m->message_id.is_valid() && m->message_id.is_server());
|
||||
TRY_STATUS_PROMISE(promise, m->reply_markup->check_shared_dialog_count(button_id, shared_dialog_ids.size()));
|
||||
for (auto shared_dialog_id : shared_dialog_ids) {
|
||||
if (shared_dialog_id.get_type() != DialogType::User) {
|
||||
if (!have_dialog_force(shared_dialog_id, "share_dialog_with_bot")) {
|
||||
if (!have_dialog_force(shared_dialog_id, "share_dialogs_with_bot")) {
|
||||
return promise.set_error(Status::Error(400, "Shared chat not found"));
|
||||
}
|
||||
} else {
|
||||
@ -28639,13 +28644,14 @@ void MessagesManager::share_dialog_with_bot(MessageFullId message_full_id, int32
|
||||
}
|
||||
}
|
||||
TRY_STATUS_PROMISE(promise, m->reply_markup->check_shared_dialog(td_, button_id, shared_dialog_id));
|
||||
}
|
||||
|
||||
if (only_check) {
|
||||
return promise.set_value(Unit());
|
||||
}
|
||||
|
||||
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(
|
||||
|
@ -479,7 +479,7 @@ class MessagesManager final : public Actor {
|
||||
|
||||
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);
|
||||
|
||||
Result<MessageId> add_local_message(
|
||||
|
@ -1149,6 +1149,17 @@ Status ReplyMarkup::check_shared_dialog(Td *td, int32 button_id, DialogId dialog
|
||||
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,
|
||||
const unique_ptr<ReplyMarkup> &reply_markup) {
|
||||
if (reply_markup == nullptr) {
|
||||
|
@ -91,6 +91,8 @@ struct ReplyMarkup {
|
||||
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_count(int32 button_id, size_t count) const;
|
||||
};
|
||||
|
||||
bool operator==(const ReplyMarkup &lhs, const ReplyMarkup &rhs);
|
||||
|
@ -16,7 +16,7 @@ RequestedDialogType::RequestedDialogType(td_api::object_ptr<td_api::keyboardButt
|
||||
CHECK(request_users != nullptr);
|
||||
type_ = Type::User;
|
||||
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_;
|
||||
is_bot_ = request_users->user_is_bot_;
|
||||
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) {
|
||||
CHECK(peer_type != nullptr);
|
||||
button_id_ = button_id;
|
||||
max_quantity_ = max_quantity;
|
||||
max_quantity_ = max(max_quantity, 1);
|
||||
switch (peer_type->get_id()) {
|
||||
case telegram_api::requestPeerTypeUser::ID: {
|
||||
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();
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -59,6 +59,8 @@ class RequestedDialogType {
|
||||
|
||||
Status check_shared_dialog(Td *td, DialogId dialog_id) const;
|
||||
|
||||
Status check_shared_dialog_count(size_t count) const;
|
||||
|
||||
template <class StorerT>
|
||||
void store(StorerT &storer) const;
|
||||
|
||||
|
@ -8388,19 +8388,21 @@ void Td::on_request(uint64 id, const td_api::getLoginUrl &request) {
|
||||
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();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
messages_manager_->share_dialog_with_bot({DialogId(request.chat_id_), MessageId(request.message_id_)},
|
||||
request.button_id_, DialogId(UserId(request.shared_user_id_)), true,
|
||||
request.only_check_, std::move(promise));
|
||||
auto user_ids = UserId::get_user_ids(request.shared_user_ids_);
|
||||
auto dialog_ids = transform(user_ids, [](UserId user_id) { return DialogId(user_id); });
|
||||
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) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
messages_manager_->share_dialog_with_bot({DialogId(request.chat_id_), MessageId(request.message_id_)},
|
||||
request.button_id_, DialogId(request.shared_chat_id_), false,
|
||||
messages_manager_->share_dialogs_with_bot({DialogId(request.chat_id_), MessageId(request.message_id_)},
|
||||
request.button_id_, {DialogId(request.shared_chat_id_)}, false,
|
||||
request.only_check_, std::move(promise));
|
||||
}
|
||||
|
||||
|
@ -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::shareUserWithBot &request);
|
||||
void on_request(uint64 id, const td_api::shareUsersWithBot &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::shareChatWithBot &request);
|
||||
|
||||
|
@ -6095,10 +6095,10 @@ class CliClient final : public Actor {
|
||||
ChatId chat_id;
|
||||
MessageId message_id;
|
||||
int32 button_id;
|
||||
UserId shared_user_id;
|
||||
get_args(args, chat_id, message_id, button_id, shared_user_id);
|
||||
send_request(
|
||||
td_api::make_object<td_api::shareUserWithBot>(chat_id, message_id, button_id, shared_user_id, op == "suwbc"));
|
||||
string shared_user_ids;
|
||||
get_args(args, chat_id, message_id, button_id, shared_user_ids);
|
||||
send_request(td_api::make_object<td_api::shareUsersWithBot>(chat_id, message_id, button_id,
|
||||
as_user_ids(shared_user_ids), op == "suwbc"));
|
||||
} else if (op == "scwb" || op == "scwbc") {
|
||||
ChatId chat_id;
|
||||
MessageId message_id;
|
||||
|
Loading…
Reference in New Issue
Block a user