Add MessageOrigin::hide_sender_if_needed.

This commit is contained in:
levlam 2023-10-09 21:24:22 +03:00
parent b10220a495
commit 21068870f0
3 changed files with 14 additions and 9 deletions

View File

@ -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_);

View File

@ -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<UserId> &user_ids) const;

View File

@ -27976,15 +27976,8 @@ Result<td_api::object_ptr<td_api::messages>> 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()) {