From 21068870f04d899eaa30008a965f77c7c41fa625 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 9 Oct 2023 21:24:22 +0300 Subject: [PATCH] Add MessageOrigin::hide_sender_if_needed. --- td/telegram/MessageOrigin.cpp | 10 ++++++++++ td/telegram/MessageOrigin.h | 2 ++ td/telegram/MessagesManager.cpp | 11 ++--------- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/td/telegram/MessageOrigin.cpp b/td/telegram/MessageOrigin.cpp index a55597e1d..a62e37887 100644 --- a/td/telegram/MessageOrigin.cpp +++ b/td/telegram/MessageOrigin.cpp @@ -117,6 +117,16 @@ DialogId MessageOrigin::get_sender() const { return message_id_.is_valid() || sender_dialog_id_.is_valid() ? sender_dialog_id_ : DialogId(sender_user_id_); } +void MessageOrigin::hide_sender_if_needed(Td *td) { + if (!is_sender_hidden() && !message_id_.is_valid() && !sender_dialog_id_.is_valid()) { + auto private_forward_name = td->contacts_manager_->get_user_private_forward_name(sender_user_id_); + if (!private_forward_name.empty()) { + sender_user_id_ = UserId(); + sender_name_ = std::move(private_forward_name); + } + } +} + void MessageOrigin::add_dependencies(Dependencies &dependencies) const { dependencies.add(sender_user_id_); dependencies.add_dialog_and_dependencies(sender_dialog_id_); diff --git a/td/telegram/MessageOrigin.h b/td/telegram/MessageOrigin.h index e729a5e6e..8de05818e 100644 --- a/td/telegram/MessageOrigin.h +++ b/td/telegram/MessageOrigin.h @@ -65,6 +65,8 @@ struct MessageOrigin { DialogId get_sender() const; + void hide_sender_if_needed(Td *td); + void add_dependencies(Dependencies &dependencies) const; void add_user_ids(vector &user_ids) const; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 444cd0983..41e74ff63 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -27976,15 +27976,8 @@ Result> MessagesManager::forward_messages( auto content = std::move(forwarded_message_contents[j].content); auto forward_info = drop_author ? nullptr : create_message_forward_info(from_dialog_id, to_dialog_id, forwarded_message); - if (forward_info != nullptr && !forward_info->is_imported && !is_forward_info_sender_hidden(forward_info.get()) && - !forward_info->origin.message_id_.is_valid() && !forward_info->origin.sender_dialog_id_.is_valid() && - forward_info->origin.sender_user_id_.is_valid()) { - auto private_forward_name = - td_->contacts_manager_->get_user_private_forward_name(forward_info->origin.sender_user_id_); - if (!private_forward_name.empty()) { - forward_info->origin.sender_user_id_ = UserId(); - forward_info->origin.sender_name_ = std::move(private_forward_name); - } + if (forward_info != nullptr && !forward_info->is_imported) { + forward_info->origin.hide_sender_if_needed(td_); } MessageId reply_to_message_id; if (forwarded_message->reply_to_message_id.is_valid() && forwarded_message->reply_in_dialog_id == DialogId()) {