From 8adea20fd3c5fbb31e967cada8c53c3829c5d038 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 27 Oct 2023 14:33:15 +0300 Subject: [PATCH] Keep quote when forwarding replies. --- td/telegram/MessagesManager.cpp | 14 +++++++------- td/telegram/RepliedMessageInfo.cpp | 7 +++++++ td/telegram/RepliedMessageInfo.h | 2 ++ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 6e2dbc883..1a14ba4c9 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -28102,12 +28102,13 @@ Result> MessagesManager::forward_messages( if (forward_info != nullptr && !forward_info->is_imported) { forward_info->origin.hide_sender_if_needed(td_); } - MessageId reply_to_message_id; + MessageInputReplyTo input_reply_to; auto original_reply_to_message_id = forwarded_message->replied_message_info.get_same_chat_reply_to_message_id(); if (original_reply_to_message_id.is_valid()) { auto it = forwarded_message_id_to_new_message_id.find(original_reply_to_message_id); if (it != forwarded_message_id_to_new_message_id.end()) { - reply_to_message_id = it->second; + input_reply_to = forwarded_message->replied_message_info.get_input_reply_to(); + input_reply_to.set_message_id(it->second); } } @@ -28115,9 +28116,9 @@ Result> MessagesManager::forward_messages( Message *m; if (message_send_options.only_preview) { message = create_message_to_send( - to_dialog, top_thread_message_id, MessageInputReplyTo{reply_to_message_id, FormattedText()}, - message_send_options, std::move(content), forwarded_message_contents[j].invert_media, - j + 1 != forwarded_message_contents.size(), std::move(forward_info), false, DialogId()); + to_dialog, top_thread_message_id, std::move(input_reply_to), message_send_options, std::move(content), + forwarded_message_contents[j].invert_media, j + 1 != forwarded_message_contents.size(), + std::move(forward_info), false, DialogId()); MessageId new_message_id = message_send_options.schedule_date != 0 ? get_next_yet_unsent_scheduled_message_id(to_dialog, message_send_options.schedule_date) @@ -28125,8 +28126,7 @@ Result> MessagesManager::forward_messages( message->message_id = new_message_id; m = message.get(); } else { - m = get_message_to_send(to_dialog, top_thread_message_id, - MessageInputReplyTo{reply_to_message_id, FormattedText()}, message_send_options, + m = get_message_to_send(to_dialog, top_thread_message_id, std::move(input_reply_to), message_send_options, std::move(content), forwarded_message_contents[j].invert_media, &need_update_dialog_pos, j + 1 != forwarded_message_contents.size(), std::move(forward_info)); } diff --git a/td/telegram/RepliedMessageInfo.cpp b/td/telegram/RepliedMessageInfo.cpp index 70228dd5d..d11419bf4 100644 --- a/td/telegram/RepliedMessageInfo.cpp +++ b/td/telegram/RepliedMessageInfo.cpp @@ -292,6 +292,13 @@ td_api::object_ptr RepliedMessageInfo::get_messag std::move(content)); } +MessageInputReplyTo RepliedMessageInfo::get_input_reply_to() const { + if (message_id_.is_valid() && dialog_id_ == DialogId()) { + return MessageInputReplyTo{message_id_, FormattedText{quote_}}; + } + return {}; +} + MessageId RepliedMessageInfo::get_same_chat_reply_to_message_id() const { return is_same_chat_reply() ? message_id_ : MessageId(); } diff --git a/td/telegram/RepliedMessageInfo.h b/td/telegram/RepliedMessageInfo.h index f7cc9ad95..0bc18c0cb 100644 --- a/td/telegram/RepliedMessageInfo.h +++ b/td/telegram/RepliedMessageInfo.h @@ -87,6 +87,8 @@ class RepliedMessageInfo { td_api::object_ptr get_message_reply_to_message_object(Td *td, DialogId dialog_id) const; + MessageInputReplyTo get_input_reply_to() const; + void set_message_id(MessageId new_message_id) { CHECK(message_id_.is_valid() || message_id_.is_valid_scheduled()); message_id_ = new_message_id;