From 5b2dd42e5898258621a9e1ec8143d2a1049a5303 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 29 Oct 2023 22:14:41 +0300 Subject: [PATCH] Init RepliedMessageInfo fields for sent replies to messages in other chats. --- td/telegram/MessagesManager.cpp | 15 +++++++++++++++ td/telegram/MessagesManager.h | 7 +++++++ td/telegram/RepliedMessageInfo.cpp | 20 ++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 0b193dd36..d6b1a194e 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -24574,6 +24574,20 @@ MessageInputReplyTo MessagesManager::get_message_input_reply_to( } } +MessagesManager::ForwardedMessageInfo MessagesManager::get_forwarded_message_info(MessageFullId message_full_id) { + ForwardedMessageInfo result; + auto *m = get_message_force(message_full_id, "get_forwarded_message_info"); + if (m == nullptr || m->message_id.is_scheduled()) { + return result; + } + auto dialog_id = message_full_id.get_dialog_id(); + result.origin_date_ = m->forward_info != nullptr ? m->forward_info->date : m->date; + result.origin_ = get_forwarded_message_origin(dialog_id, m); + result.content_ = + dup_message_content(td_, dialog_id, m->content.get(), MessageContentDupType::Forward, MessageCopyOptions()); + return result; +} + const MessageInputReplyTo *MessagesManager::get_message_input_reply_to(const Message *m) { CHECK(m != nullptr); CHECK(!m->message_id.is_server()); @@ -27763,6 +27777,7 @@ Result> MessagesManager::forward_message( } MessageOrigin MessagesManager::get_forwarded_message_origin(DialogId dialog_id, const Message *m) const { + CHECK(m != nullptr); if (m->forward_info != nullptr) { return m->forward_info->origin; } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 696dc5f8d..c3d85466e 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -431,6 +431,13 @@ class MessagesManager final : public Actor { DialogId get_dialog_default_send_message_as_dialog_id(DialogId dialog_id) const; + struct ForwardedMessageInfo { + int32 origin_date_ = 0; + MessageOrigin origin_; + unique_ptr content_; + }; + ForwardedMessageInfo get_forwarded_message_info(MessageFullId message_full_id); + MessageInputReplyTo get_message_input_reply_to(DialogId dialog_id, MessageId top_thread_message_id, td_api::object_ptr &&reply_to, bool for_draft); diff --git a/td/telegram/RepliedMessageInfo.cpp b/td/telegram/RepliedMessageInfo.cpp index 538c18e54..4613c85b5 100644 --- a/td/telegram/RepliedMessageInfo.cpp +++ b/td/telegram/RepliedMessageInfo.cpp @@ -158,6 +158,26 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, const MessageInputReplyTo &input_ is_quote_manual_ = true; } if (input_reply_to.dialog_id_ != DialogId()) { + auto info = + td->messages_manager_->get_forwarded_message_info({input_reply_to.dialog_id_, input_reply_to.message_id_}); + if (info.origin_date_ == 0 || info.origin_.is_empty() || info.content_ == nullptr) { + *this = {}; + return; + } + origin_date_ = info.origin_date_; + origin_ = std::move(info.origin_); + content_ = std::move(info.content_); + auto content_text = get_message_content_text_mutable(content_.get()); + if (content_text != nullptr) { + if (!is_quote_manual_) { + quote_ = std::move(*content_text); + remove_unallowed_quote_entities(quote_); + truncate_formatted_text( + quote_, static_cast(td->option_manager_->get_option_integer("message_reply_quote_length_max"))); + } + *content_text = {}; + } + if (input_reply_to.dialog_id_.get_type() == DialogType::Channel) { dialog_id_ = input_reply_to.dialog_id_; } else {