Disallow MessageInputReplyTo copying.

This commit is contained in:
levlam 2023-10-27 03:37:26 +03:00
parent 6517d6b9db
commit d43fd3beb3
6 changed files with 36 additions and 49 deletions

View File

@ -198,7 +198,7 @@ class RequestWebViewQuery final : public Td::ResultHandler {
auto ptr = result_ptr.move_as_ok(); auto ptr = result_ptr.move_as_ok();
td_->attach_menu_manager_->open_web_view(ptr->query_id_, dialog_id_, bot_user_id_, top_thread_message_id_, td_->attach_menu_manager_->open_web_view(ptr->query_id_, dialog_id_, bot_user_id_, top_thread_message_id_,
input_reply_to_, as_dialog_id_); std::move(input_reply_to_), as_dialog_id_);
promise_.set_value(td_api::make_object<td_api::webAppInfo>(ptr->query_id_, ptr->url_)); promise_.set_value(td_api::make_object<td_api::webAppInfo>(ptr->query_id_, ptr->url_));
} }
@ -217,7 +217,7 @@ class ProlongWebViewQuery final : public Td::ResultHandler {
public: public:
void send(DialogId dialog_id, UserId bot_user_id, int64 query_id, MessageId top_thread_message_id, void send(DialogId dialog_id, UserId bot_user_id, int64 query_id, MessageId top_thread_message_id,
MessageInputReplyTo input_reply_to, bool silent, DialogId as_dialog_id) { const MessageInputReplyTo &input_reply_to, bool silent, DialogId as_dialog_id) {
dialog_id_ = dialog_id; dialog_id_ = 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);
@ -876,11 +876,11 @@ void AttachMenuManager::request_web_view(DialogId dialog_id, UserId bot_user_id,
td_->create_handler<RequestWebViewQuery>(std::move(promise)) td_->create_handler<RequestWebViewQuery>(std::move(promise))
->send(dialog_id, bot_user_id, std::move(input_user), std::move(url), std::move(theme), std::move(platform), ->send(dialog_id, bot_user_id, std::move(input_user), std::move(url), std::move(theme), std::move(platform),
top_thread_message_id, input_reply_to, silent, as_dialog_id); top_thread_message_id, std::move(input_reply_to), silent, as_dialog_id);
} }
void AttachMenuManager::open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id, void AttachMenuManager::open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id,
MessageId top_thread_message_id, MessageInputReplyTo input_reply_to, MessageId top_thread_message_id, MessageInputReplyTo &&input_reply_to,
DialogId as_dialog_id) { DialogId as_dialog_id) {
if (query_id == 0) { if (query_id == 0) {
LOG(ERROR) << "Receive Web App query identifier == 0"; LOG(ERROR) << "Receive Web App query identifier == 0";

View File

@ -48,7 +48,7 @@ class AttachMenuManager final : public Actor {
Promise<td_api::object_ptr<td_api::webAppInfo>> &&promise); Promise<td_api::object_ptr<td_api::webAppInfo>> &&promise);
void open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id, MessageId top_thread_message_id, void open_web_view(int64 query_id, DialogId dialog_id, UserId bot_user_id, MessageId top_thread_message_id,
MessageInputReplyTo input_reply_to, DialogId as_dialog_id); MessageInputReplyTo &&input_reply_to, DialogId as_dialog_id);
void close_web_view(int64 query_id, Promise<Unit> &&promise); void close_web_view(int64 query_id, Promise<Unit> &&promise);

View File

@ -16,27 +16,8 @@
#include "td/utils/logging.h" #include "td/utils/logging.h"
namespace td { namespace td {
/*
MessageInputReplyTo::MessageInputReplyTo(const td_api::object_ptr<td_api::InputMessageReplyTo> &reply_to_ptr) { MessageInputReplyTo::~MessageInputReplyTo() = default;
if (reply_to_ptr == nullptr) {
return;
}
switch (reply_to_ptr->get_id()) {
case td_api::inputMessageReplyToMessage::ID: {
auto reply_to = static_cast<const td_api::inputMessageReplyToMessage *>(reply_to_ptr.get());
message_id_ = MessageId(reply_to->message_id_);
break;
}
case td_api::inputMessageReplyToStory::ID: {
auto reply_to = static_cast<const td_api::inputMessageReplyToStory *>(reply_to_ptr.get());
story_full_id_ = {DialogId(reply_to->story_sender_chat_id_), StoryId(reply_to->story_id_)};
break;
}
default:
UNREACHABLE();
}
}
*/
MessageInputReplyTo::MessageInputReplyTo(Td *td, MessageInputReplyTo::MessageInputReplyTo(Td *td,
telegram_api::object_ptr<telegram_api::InputReplyTo> &&input_reply_to) { telegram_api::object_ptr<telegram_api::InputReplyTo> &&input_reply_to) {

View File

@ -33,6 +33,11 @@ class MessageInputReplyTo {
public: public:
MessageInputReplyTo() = default; MessageInputReplyTo() = default;
MessageInputReplyTo(const MessageInputReplyTo &) = delete;
MessageInputReplyTo &operator=(const MessageInputReplyTo &) = delete;
MessageInputReplyTo(MessageInputReplyTo &&) = default;
MessageInputReplyTo &operator=(MessageInputReplyTo &&) = default;
~MessageInputReplyTo();
explicit MessageInputReplyTo(MessageId message_id) : message_id_(message_id) { explicit MessageInputReplyTo(MessageId message_id) : message_id_(message_id) {
} }

View File

@ -24259,7 +24259,7 @@ int64 MessagesManager::generate_new_random_id(const Dialog *d) {
} }
unique_ptr<MessagesManager::Message> MessagesManager::create_message_to_send( unique_ptr<MessagesManager::Message> MessagesManager::create_message_to_send(
Dialog *d, MessageId top_thread_message_id, MessageInputReplyTo input_reply_to, const MessageSendOptions &options, Dialog *d, MessageId top_thread_message_id, MessageInputReplyTo &&input_reply_to, const MessageSendOptions &options,
unique_ptr<MessageContent> &&content, bool invert_media, bool suppress_reply_info, unique_ptr<MessageContent> &&content, bool invert_media, bool suppress_reply_info,
unique_ptr<MessageForwardInfo> forward_info, bool is_copy, DialogId send_as_dialog_id) const { unique_ptr<MessageForwardInfo> forward_info, bool is_copy, DialogId send_as_dialog_id) const {
CHECK(d != nullptr); CHECK(d != nullptr);
@ -24401,14 +24401,14 @@ unique_ptr<MessagesManager::Message> MessagesManager::create_message_to_send(
} }
MessagesManager::Message *MessagesManager::get_message_to_send( MessagesManager::Message *MessagesManager::get_message_to_send(
Dialog *d, MessageId top_thread_message_id, MessageInputReplyTo input_reply_to, const MessageSendOptions &options, Dialog *d, MessageId top_thread_message_id, MessageInputReplyTo &&input_reply_to, const MessageSendOptions &options,
unique_ptr<MessageContent> &&content, bool invert_media, bool *need_update_dialog_pos, bool suppress_reply_info, unique_ptr<MessageContent> &&content, bool invert_media, bool *need_update_dialog_pos, bool suppress_reply_info,
unique_ptr<MessageForwardInfo> forward_info, bool is_copy, DialogId send_as_dialog_id) { unique_ptr<MessageForwardInfo> forward_info, bool is_copy, DialogId send_as_dialog_id) {
d->was_opened = true; d->was_opened = true;
auto message = auto message =
create_message_to_send(d, top_thread_message_id, input_reply_to, options, std::move(content), invert_media, create_message_to_send(d, top_thread_message_id, std::move(input_reply_to), options, std::move(content),
suppress_reply_info, std::move(forward_info), is_copy, send_as_dialog_id); invert_media, suppress_reply_info, std::move(forward_info), is_copy, send_as_dialog_id);
MessageId message_id = options.schedule_date != 0 ? get_next_yet_unsent_scheduled_message_id(d, options.schedule_date) MessageId message_id = options.schedule_date != 0 ? get_next_yet_unsent_scheduled_message_id(d, options.schedule_date)
: get_next_yet_unsent_message_id(d); : get_next_yet_unsent_message_id(d);
@ -24927,8 +24927,8 @@ Result<td_api::object_ptr<td_api::message>> MessagesManager::send_message(
unique_ptr<Message> message; unique_ptr<Message> message;
Message *m; Message *m;
if (message_send_options.only_preview) { if (message_send_options.only_preview) {
message = create_message_to_send(d, top_thread_message_id, input_reply_to, message_send_options, std::move(content), message = create_message_to_send(d, top_thread_message_id, std::move(input_reply_to), message_send_options,
message_content.invert_media, false, nullptr, std::move(content), message_content.invert_media, false, nullptr,
message_content.via_bot_user_id.is_valid(), DialogId()); message_content.via_bot_user_id.is_valid(), DialogId());
MessageId new_message_id = message_send_options.schedule_date != 0 MessageId new_message_id = message_send_options.schedule_date != 0
? get_next_yet_unsent_scheduled_message_id(d, message_send_options.schedule_date) ? get_next_yet_unsent_scheduled_message_id(d, message_send_options.schedule_date)
@ -24936,8 +24936,8 @@ Result<td_api::object_ptr<td_api::message>> MessagesManager::send_message(
message->message_id = new_message_id; message->message_id = new_message_id;
m = message.get(); m = message.get();
} else { } else {
m = get_message_to_send(d, top_thread_message_id, input_reply_to, message_send_options, std::move(content), m = get_message_to_send(d, top_thread_message_id, std::move(input_reply_to), message_send_options,
message_content.invert_media, &need_update_dialog_pos, false, nullptr, std::move(content), message_content.invert_media, &need_update_dialog_pos, false, nullptr,
message_content.via_bot_user_id.is_valid()); message_content.via_bot_user_id.is_valid());
} }
m->reply_markup = std::move(message_reply_markup); m->reply_markup = std::move(message_reply_markup);
@ -25204,7 +25204,7 @@ Result<td_api::object_ptr<td_api::messages>> MessagesManager::send_message_group
unique_ptr<Message> message; unique_ptr<Message> message;
Message *m; Message *m;
if (message_send_options.only_preview) { if (message_send_options.only_preview) {
message = create_message_to_send(d, top_thread_message_id, input_reply_to, message_send_options, message = create_message_to_send(d, top_thread_message_id, std::move(input_reply_to), message_send_options,
std::move(message_content.content), message_content.invert_media, i != 0, std::move(message_content.content), message_content.invert_media, i != 0,
nullptr, false, DialogId()); nullptr, false, DialogId());
MessageId new_message_id = message_send_options.schedule_date != 0 MessageId new_message_id = message_send_options.schedule_date != 0
@ -25213,7 +25213,7 @@ Result<td_api::object_ptr<td_api::messages>> MessagesManager::send_message_group
message->message_id = new_message_id; message->message_id = new_message_id;
m = message.get(); m = message.get();
} else { } else {
m = get_message_to_send(d, top_thread_message_id, input_reply_to, message_send_options, m = get_message_to_send(d, top_thread_message_id, std::move(input_reply_to), message_send_options,
dup_message_content(td_, dialog_id, message_content.content.get(), dup_message_content(td_, dialog_id, message_content.content.get(),
MessageContentDupType::Send, MessageCopyOptions()), MessageContentDupType::Send, MessageCopyOptions()),
message_content.invert_media, &need_update_dialog_pos, i != 0); message_content.invert_media, &need_update_dialog_pos, i != 0);
@ -26098,7 +26098,7 @@ Result<td_api::object_ptr<td_api::message>> MessagesManager::send_inline_query_r
Message *m; Message *m;
if (message_send_options.only_preview) { if (message_send_options.only_preview) {
message = message =
create_message_to_send(d, top_thread_message_id, input_reply_to, message_send_options, create_message_to_send(d, top_thread_message_id, std::move(input_reply_to), message_send_options,
std::move(message_content), content->invert_media, false, nullptr, true, DialogId()); std::move(message_content), content->invert_media, false, nullptr, true, DialogId());
MessageId new_message_id = message_send_options.schedule_date != 0 MessageId new_message_id = message_send_options.schedule_date != 0
? get_next_yet_unsent_scheduled_message_id(d, message_send_options.schedule_date) ? get_next_yet_unsent_scheduled_message_id(d, message_send_options.schedule_date)
@ -26106,8 +26106,9 @@ Result<td_api::object_ptr<td_api::message>> MessagesManager::send_inline_query_r
message->message_id = new_message_id; message->message_id = new_message_id;
m = message.get(); m = message.get();
} else { } else {
m = get_message_to_send(d, top_thread_message_id, input_reply_to, message_send_options, std::move(message_content), m = get_message_to_send(d, top_thread_message_id, std::move(input_reply_to), message_send_options,
content->invert_media, &need_update_dialog_pos, false, nullptr, true); std::move(message_content), content->invert_media, &need_update_dialog_pos, false, nullptr,
true);
} }
m->hide_via_bot = hide_via_bot; m->hide_via_bot = hide_via_bot;
@ -28002,7 +28003,7 @@ Result<MessagesManager::ForwardedMessages> MessagesManager::get_forwarded_messag
if (is_local_copy) { if (is_local_copy) {
auto original_reply_to_message_id = forwarded_message->replied_message_info.get_same_chat_reply_to_message_id(); auto original_reply_to_message_id = forwarded_message->replied_message_info.get_same_chat_reply_to_message_id();
copied_messages.push_back( copied_messages.push_back(
{std::move(content), input_reply_to, forwarded_message->message_id, original_reply_to_message_id, {std::move(content), std::move(input_reply_to), forwarded_message->message_id, original_reply_to_message_id,
std::move(reply_markup), forwarded_message->media_album_id, std::move(reply_markup), forwarded_message->media_album_id,
get_message_disable_web_page_preview(forwarded_message), forwarded_message->invert_media, i}); get_message_disable_web_page_preview(forwarded_message), forwarded_message->invert_media, i});
} else { } else {
@ -28148,7 +28149,7 @@ Result<td_api::object_ptr<td_api::messages>> MessagesManager::forward_messages(
forwarded_message_id_to_new_message_id.emplace(copied_message.original_message_id, MessageId()); forwarded_message_id_to_new_message_id.emplace(copied_message.original_message_id, MessageId());
} }
for (auto &copied_message : copied_messages) { for (auto &copied_message : copied_messages) {
auto input_reply_to = copied_message.input_reply_to; auto input_reply_to = std::move(copied_message.input_reply_to);
if (!input_reply_to.is_valid() && copied_message.original_reply_to_message_id.is_valid() && is_secret) { if (!input_reply_to.is_valid() && copied_message.original_reply_to_message_id.is_valid() && is_secret) {
auto it = forwarded_message_id_to_new_message_id.find(copied_message.original_reply_to_message_id); auto it = forwarded_message_id_to_new_message_id.find(copied_message.original_reply_to_message_id);
if (it != forwarded_message_id_to_new_message_id.end()) { if (it != forwarded_message_id_to_new_message_id.end()) {
@ -28159,9 +28160,9 @@ Result<td_api::object_ptr<td_api::messages>> MessagesManager::forward_messages(
unique_ptr<Message> message; unique_ptr<Message> message;
Message *m; Message *m;
if (message_send_options.only_preview) { if (message_send_options.only_preview) {
message = create_message_to_send(to_dialog, top_thread_message_id, input_reply_to, message_send_options, message = create_message_to_send(to_dialog, top_thread_message_id, std::move(input_reply_to),
std::move(copied_message.content), copied_message.invert_media, false, nullptr, message_send_options, std::move(copied_message.content),
is_copy, DialogId()); copied_message.invert_media, false, nullptr, is_copy, DialogId());
MessageId new_message_id = MessageId new_message_id =
message_send_options.schedule_date != 0 message_send_options.schedule_date != 0
? get_next_yet_unsent_scheduled_message_id(to_dialog, message_send_options.schedule_date) ? get_next_yet_unsent_scheduled_message_id(to_dialog, message_send_options.schedule_date)
@ -28175,7 +28176,7 @@ Result<td_api::object_ptr<td_api::messages>> MessagesManager::forward_messages(
extract_authentication_codes(from_dialog_id, forwarded_message, authentication_codes); extract_authentication_codes(from_dialog_id, forwarded_message, authentication_codes);
} }
m = get_message_to_send(to_dialog, top_thread_message_id, input_reply_to, message_send_options, m = get_message_to_send(to_dialog, top_thread_message_id, std::move(input_reply_to), message_send_options,
std::move(copied_message.content), copied_message.invert_media, &need_update_dialog_pos, std::move(copied_message.content), copied_message.invert_media, &need_update_dialog_pos,
false, nullptr, is_copy); false, nullptr, is_copy);
} }
@ -28300,7 +28301,7 @@ Result<vector<MessageId>> MessagesManager::resend_messages(DialogId dialog_id, v
message->update_stickersets_order, message->noforwards, false, message->update_stickersets_order, message->noforwards, false,
get_message_schedule_date(message.get()), message->sending_id); get_message_schedule_date(message.get()), message->sending_id);
Message *m = Message *m =
get_message_to_send(d, message->top_thread_message_id, *get_message_input_reply_to(message.get()), options, get_message_to_send(d, message->top_thread_message_id, std::move(message->input_reply_to), options,
std::move(new_contents[i]), message->invert_media, &need_update_dialog_pos, false, nullptr, std::move(new_contents[i]), message->invert_media, &need_update_dialog_pos, false, nullptr,
message->is_copy, need_another_sender ? DialogId() : get_message_sender(message.get())); message->is_copy, need_another_sender ? DialogId() : get_message_sender(message.get()));
m->reply_markup = std::move(message->reply_markup); m->reply_markup = std::move(message->reply_markup);
@ -30834,7 +30835,7 @@ MessageFullId MessagesManager::on_send_message_success(int64 random_id, MessageI
} }
const auto *input_reply_to = get_message_input_reply_to(sent_message.get()); const auto *input_reply_to = get_message_input_reply_to(sent_message.get());
if (input_reply_to->is_valid() && if (input_reply_to != nullptr && input_reply_to->is_valid() &&
input_reply_to->get_reply_message_full_id(dialog_id).get_message_id().is_yet_unsent()) { input_reply_to->get_reply_message_full_id(dialog_id).get_message_id().is_yet_unsent()) {
set_message_reply(d, sent_message.get(), MessageId(), false); set_message_reply(d, sent_message.get(), MessageId(), false);
} }

View File

@ -1798,12 +1798,12 @@ class MessagesManager final : public Actor {
int64 generate_new_random_id(const Dialog *d); int64 generate_new_random_id(const Dialog *d);
unique_ptr<Message> create_message_to_send(Dialog *d, MessageId top_thread_message_id, unique_ptr<Message> create_message_to_send(Dialog *d, MessageId top_thread_message_id,
MessageInputReplyTo input_reply_to, const MessageSendOptions &options, MessageInputReplyTo &&input_reply_to, const MessageSendOptions &options,
unique_ptr<MessageContent> &&content, bool invert_media, unique_ptr<MessageContent> &&content, bool invert_media,
bool suppress_reply_info, unique_ptr<MessageForwardInfo> forward_info, bool suppress_reply_info, unique_ptr<MessageForwardInfo> forward_info,
bool is_copy, DialogId send_as_dialog_id) const; bool is_copy, DialogId send_as_dialog_id) const;
Message *get_message_to_send(Dialog *d, MessageId top_thread_message_id, MessageInputReplyTo input_reply_to, Message *get_message_to_send(Dialog *d, MessageId top_thread_message_id, MessageInputReplyTo &&input_reply_to,
const MessageSendOptions &options, unique_ptr<MessageContent> &&content, const MessageSendOptions &options, unique_ptr<MessageContent> &&content,
bool invert_media, bool *need_update_dialog_pos, bool suppress_reply_info = false, bool invert_media, bool *need_update_dialog_pos, bool suppress_reply_info = false,
unique_ptr<MessageForwardInfo> forward_info = nullptr, bool is_copy = false, unique_ptr<MessageForwardInfo> forward_info = nullptr, bool is_copy = false,