Init RepliedMessageInfo fields for sent replies to messages in other chats.

This commit is contained in:
levlam 2023-10-29 22:14:41 +03:00
parent 0ad0f7cdcc
commit 5b2dd42e58
3 changed files with 42 additions and 0 deletions

View File

@ -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<td_api::object_ptr<td_api::message>> 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;
}

View File

@ -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<MessageContent> 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<td_api::InputMessageReplyTo> &&reply_to,
bool for_draft);

View File

@ -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<size_t>(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 {