Duplicate fields from origin to source if appropriate.

This commit is contained in:
levlam 2024-01-15 18:56:59 +03:00
parent 85c4cd4642
commit 341b59cb6c
3 changed files with 26 additions and 8 deletions

View File

@ -67,11 +67,22 @@ void LastForwardedMessageInfo::add_min_channel_ids(vector<ChannelId> &channel_id
}
}
td_api::object_ptr<td_api::forwardSource> LastForwardedMessageInfo::get_forward_source_object(Td *td) const {
td_api::object_ptr<td_api::forwardSource> LastForwardedMessageInfo::get_forward_source_object(
Td *td, bool for_saved_messages, const MessageOrigin &origin, int32 origin_date) const {
if (is_empty()) {
return nullptr;
}
td_api::object_ptr<td_api::MessageSender> sender_id;
if (date_ == 0 && for_saved_messages) {
auto sender_dialog_id = origin.get_sender();
if (sender_dialog_id.is_valid()) {
sender_id = get_message_sender_object_const(td, sender_dialog_id, "origin.forwardSource.sender_id");
}
return td_api::make_object<td_api::forwardSource>(
td->messages_manager_->get_chat_id_object(dialog_id_, "forwardSource.chat_id"), message_id_.get(),
std::move(sender_id), origin.get_sender_name(), origin_date, is_outgoing_);
}
if (sender_dialog_id_ != DialogId()) {
sender_id = get_message_sender_object_const(td, sender_dialog_id_, "forwardSource.sender_id");
}
@ -159,12 +170,14 @@ unique_ptr<MessageForwardInfo> MessageForwardInfo::copy_message_forward_info(
return result;
}
td_api::object_ptr<td_api::messageForwardInfo> MessageForwardInfo::get_message_forward_info_object(Td *td) const {
td_api::object_ptr<td_api::messageForwardInfo> MessageForwardInfo::get_message_forward_info_object(
Td *td, bool for_saved_messages) const {
if (is_imported_) {
return nullptr;
}
return td_api::make_object<td_api::messageForwardInfo>(origin_.get_message_origin_object(td), date_,
last_message_info_.get_forward_source_object(td), psa_type_);
return td_api::make_object<td_api::messageForwardInfo>(
origin_.get_message_origin_object(td), date_,
last_message_info_.get_forward_source_object(td, for_saved_messages, origin_, date_), psa_type_);
}
td_api::object_ptr<td_api::messageImportInfo> MessageForwardInfo::get_message_import_info_object() const {

View File

@ -60,7 +60,9 @@ class LastForwardedMessageInfo {
void add_min_channel_ids(vector<ChannelId> &channel_ids) const;
td_api::object_ptr<td_api::forwardSource> get_forward_source_object(Td *td) const;
td_api::object_ptr<td_api::forwardSource> get_forward_source_object(Td *td, bool for_saved_messages,
const MessageOrigin &origin,
int32 origin_date) const;
DialogId get_dialog_id() const {
return dialog_id_;
@ -111,7 +113,7 @@ class MessageForwardInfo {
static unique_ptr<MessageForwardInfo> copy_message_forward_info(Td *td, const MessageForwardInfo &forward_info,
LastForwardedMessageInfo &&last_message_info);
td_api::object_ptr<td_api::messageForwardInfo> get_message_forward_info_object(Td *td) const;
td_api::object_ptr<td_api::messageForwardInfo> get_message_forward_info_object(Td *td, bool for_saved_messages) const;
td_api::object_ptr<td_api::messageImportInfo> get_message_import_info_object() const;

View File

@ -22225,7 +22225,8 @@ td_api::object_ptr<td_api::message> MessagesManager::get_dialog_event_log_messag
auto sender = get_message_sender_object_const(td_, m->sender_user_id, m->sender_dialog_id,
"get_dialog_event_log_message_object");
auto forward_info = m->forward_info == nullptr ? nullptr : m->forward_info->get_message_forward_info_object(td_);
auto forward_info =
m->forward_info == nullptr ? nullptr : m->forward_info->get_message_forward_info_object(td_, false);
auto import_info = m->forward_info == nullptr ? nullptr : m->forward_info->get_message_import_info_object();
auto interaction_info = get_message_interaction_info_object(dialog_id, m);
auto can_be_saved = can_save_message(dialog_id, m);
@ -22301,7 +22302,9 @@ tl_object_ptr<td_api::message> MessagesManager::get_message_object(DialogId dial
m->ttl_period == 0 ? 0.0 : clamp(m->date + m->ttl_period - G()->server_time(), 1e-3, m->ttl_period - 1e-3);
auto sender = get_message_sender_object_const(td_, m->sender_user_id, m->sender_dialog_id, source);
auto scheduling_state = is_scheduled ? get_message_scheduling_state_object(m->date) : nullptr;
auto forward_info = m->forward_info == nullptr ? nullptr : m->forward_info->get_message_forward_info_object(td_);
auto forward_info = m->forward_info == nullptr
? nullptr
: m->forward_info->get_message_forward_info_object(td_, dialog_id == my_dialog_id);
auto import_info = m->forward_info == nullptr ? nullptr : m->forward_info->get_message_import_info_object();
auto interaction_info = is_bot ? nullptr : get_message_interaction_info_object(dialog_id, m);
auto unread_reactions = get_unread_reactions_object(dialog_id, m);