Add and use MessageOrigin::get_sender.

This commit is contained in:
levlam 2023-10-09 20:06:23 +03:00
parent 8da2eba168
commit 7b1408d44e
3 changed files with 16 additions and 10 deletions

View File

@ -103,6 +103,13 @@ bool MessageOrigin::is_sender_hidden() const {
return sender_dialog_id_ == hidden_sender_dialog_id && !author_signature_.empty() && !message_id_.is_valid();
}
DialogId MessageOrigin::get_sender() const {
if (is_sender_hidden()) {
return DialogId();
}
return message_id_.is_valid() || sender_dialog_id_.is_valid() ? sender_dialog_id_ : DialogId(sender_user_id_);
}
void MessageOrigin::add_dependencies(Dependencies &dependencies) const {
dependencies.add(sender_user_id_);
dependencies.add_dialog_and_dependencies(sender_dialog_id_);

View File

@ -52,6 +52,8 @@ struct MessageOrigin {
return message_id_.is_valid();
}
DialogId get_sender() const;
void add_dependencies(Dependencies &dependencies) const;
void add_user_ids(vector<UserId> &user_ids) const;

View File

@ -17503,14 +17503,14 @@ void MessagesManager::block_message_sender_from_replies(MessageId message_id, bo
return promise.set_error(Status::Error(400, "Wrong message specified"));
}
UserId sender_user_id;
DialogId sender_dialog_id;
if (m->forward_info != nullptr) {
sender_user_id = m->forward_info->origin.sender_user_id_;
sender_dialog_id = m->forward_info->origin.get_sender();
}
vector<MessageId> message_ids;
if (need_delete_all_messages && sender_user_id.is_valid()) {
message_ids = find_dialog_messages(d, [sender_user_id](const Message *m) {
return !m->is_outgoing && m->forward_info != nullptr && m->forward_info->origin.sender_user_id_ == sender_user_id;
if (need_delete_all_messages && sender_dialog_id.is_valid()) {
message_ids = find_dialog_messages(d, [sender_dialog_id](const Message *m) {
return !m->is_outgoing && m->forward_info != nullptr && m->forward_info->origin.get_sender() == sender_dialog_id;
});
CHECK(td::contains(message_ids, message_id));
} else if (need_delete_message) {
@ -26388,13 +26388,10 @@ DialogId MessagesManager::get_message_original_sender(const Message *m) {
CHECK(m != nullptr);
if (m->forward_info != nullptr) {
auto forward_info = m->forward_info.get();
if (forward_info->is_imported || is_forward_info_sender_hidden(forward_info)) {
if (forward_info->is_imported) {
return DialogId();
}
if (forward_info->origin.message_id_.is_valid() || forward_info->origin.sender_dialog_id_.is_valid()) {
return forward_info->origin.sender_dialog_id_;
}
return DialogId(forward_info->origin.sender_user_id_);
return forward_info->origin.get_sender();
}
return get_message_sender(m);
}