Keep external replies when forwarding a message.

This commit is contained in:
levlam 2023-11-01 17:14:35 +03:00
parent 6c1fb4fe57
commit 887fd06e1c
3 changed files with 28 additions and 2 deletions

View File

@ -24584,8 +24584,8 @@ MessagesManager::ForwardedMessageInfo MessagesManager::get_forwarded_message_inf
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());
result.content_ = dup_message_content(td_, get_my_dialog_id(), m->content.get(), MessageContentDupType::Forward,
MessageCopyOptions());
return result;
}
@ -28173,6 +28173,9 @@ Result<td_api::object_ptr<td_api::messages>> MessagesManager::forward_messages(
m->real_forward_from_dialog_id = from_dialog_id;
m->real_forward_from_message_id = message_id;
forwarded_message_id_to_new_message_id.emplace(message_id, m->message_id);
if (forwarded_message->replied_message_info.is_external()) {
m->replied_message_info = forwarded_message->replied_message_info.clone(td_);
}
if (!message_send_options.only_preview) {
if (!td_->auth_manager_->is_bot()) {

View File

@ -6,6 +6,7 @@
//
#include "td/telegram/RepliedMessageInfo.h"
#include "td/telegram/ContactsManager.h"
#include "td/telegram/Dependencies.h"
#include "td/telegram/MessageContent.h"
#include "td/telegram/MessageContentType.h"
@ -188,6 +189,21 @@ RepliedMessageInfo::RepliedMessageInfo(Td *td, const MessageInputReplyTo &input_
}
}
RepliedMessageInfo RepliedMessageInfo::clone(Td *td) const {
RepliedMessageInfo result;
result.message_id_ = message_id_;
result.dialog_id_ = dialog_id_;
result.origin_date_ = origin_date_;
result.origin_ = origin_;
if (content_ != nullptr) {
result.content_ = dup_message_content(td, DialogId(td->contacts_manager_->get_my_id()), content_.get(),
MessageContentDupType::Forward, MessageCopyOptions());
}
result.quote_ = quote_;
result.is_quote_manual_ = is_quote_manual_;
return result;
}
bool RepliedMessageInfo::need_reget() const {
return content_ != nullptr && need_reget_message_content(content_.get());
}
@ -337,6 +353,7 @@ td_api::object_ptr<td_api::messageReplyToMessage> RepliedMessageInfo::get_messag
}
MessageInputReplyTo RepliedMessageInfo::get_input_reply_to() const {
CHECK(!is_external());
if (message_id_.is_valid()) {
return MessageInputReplyTo{message_id_, dialog_id_, FormattedText{quote_}};
}

View File

@ -63,11 +63,17 @@ class RepliedMessageInfo {
RepliedMessageInfo(Td *td, const MessageInputReplyTo &input_reply_to);
RepliedMessageInfo clone(Td *td) const;
bool is_empty() const {
return message_id_ == MessageId() && dialog_id_ == DialogId() && origin_date_ == 0 && origin_.is_empty() &&
quote_.text.empty() && content_ == nullptr;
}
bool is_external() const {
return origin_date_ != 0;
}
bool need_reget() const;
static bool need_reply_changed_warning(