Improve chat type check.

This commit is contained in:
levlam 2023-02-01 02:10:03 +03:00
parent b1ea693f1b
commit b067159d78
3 changed files with 9 additions and 6 deletions

View File

@ -29886,7 +29886,7 @@ void MessagesManager::do_send_screenshot_taken_notification_message(DialogId dia
}
void MessagesManager::share_dialog_with_bot(FullMessageId full_message_id, int32 button_id, DialogId shared_dialog_id,
bool only_check, Promise<Unit> &&promise) {
bool expect_user, bool only_check, Promise<Unit> &&promise) {
const Message *m = get_message_force(full_message_id, "share_dialog_with_bot");
if (m == nullptr) {
return promise.set_error(Status::Error(400, "Message not found"));
@ -29900,6 +29900,9 @@ void MessagesManager::share_dialog_with_bot(FullMessageId full_message_id, int32
return promise.set_error(Status::Error(400, "Shared chat not found"));
}
} else {
if (!expect_user) {
return promise.set_error(Status::Error(400, "Wrong chat type"));
}
if (!td_->contacts_manager_->have_user(shared_dialog_id.get_user_id())) {
return promise.set_error(Status::Error(400, "Shared user not found"));
}

View File

@ -467,8 +467,8 @@ class MessagesManager final : public Actor {
Status send_screenshot_taken_notification_message(DialogId dialog_id);
void share_dialog_with_bot(FullMessageId full_message_id, int32 button_id, DialogId shared_dialog_id, bool only_check,
Promise<Unit> &&promise);
void share_dialog_with_bot(FullMessageId full_message_id, int32 button_id, DialogId shared_dialog_id,
bool expect_user, bool only_check, Promise<Unit> &&promise);
Result<MessageId> add_local_message(DialogId dialog_id, td_api::object_ptr<td_api::MessageSender> &&sender,
MessageId reply_to_message_id, bool disable_notification,

View File

@ -7684,7 +7684,7 @@ void Td::on_request(uint64 id, const td_api::shareUserWithBot &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_)),
request.button_id_, DialogId(UserId(request.shared_user_id_)), true,
request.only_check_, std::move(promise));
}
@ -7692,8 +7692,8 @@ 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_), request.only_check_,
std::move(promise));
request.button_id_, DialogId(request.shared_chat_id_), false,
request.only_check_, std::move(promise));
}
void Td::on_request(uint64 id, td_api::getInlineQueryResults &request) {