Add and use MessageForwardInfo::need_change_warning.
This commit is contained in:
parent
edb02aa4c4
commit
c30c6168b5
@ -84,6 +84,19 @@ void MessageForwardInfo::add_min_channel_ids(vector<ChannelId> &channel_ids) con
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MessageForwardInfo::need_change_warning(const MessageForwardInfo *lhs, const MessageForwardInfo *rhs,
|
||||||
|
MessageId message_id) {
|
||||||
|
// it should be already checked that *lhs != *rhs
|
||||||
|
if (lhs == nullptr || rhs == nullptr || lhs->is_imported_ || rhs->is_imported_) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!message_id.is_scheduled() && !message_id.is_yet_unsent()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// yet unsent or scheduled messages can change sender name or author signature when being sent
|
||||||
|
return !lhs->origin_.has_sender_signature() && !rhs->origin_.has_sender_signature();
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const MessageForwardInfo &lhs, const MessageForwardInfo &rhs) {
|
bool operator==(const MessageForwardInfo &lhs, const MessageForwardInfo &rhs) {
|
||||||
return lhs.origin_ == rhs.origin_ && lhs.date_ == rhs.date_ && lhs.from_dialog_id_ == rhs.from_dialog_id_ &&
|
return lhs.origin_ == rhs.origin_ && lhs.date_ == rhs.date_ && lhs.from_dialog_id_ == rhs.from_dialog_id_ &&
|
||||||
lhs.from_message_id_ == rhs.from_message_id_ && lhs.psa_type_ == rhs.psa_type_ &&
|
lhs.from_message_id_ == rhs.from_message_id_ && lhs.psa_type_ == rhs.psa_type_ &&
|
||||||
@ -94,6 +107,17 @@ bool operator!=(const MessageForwardInfo &lhs, const MessageForwardInfo &rhs) {
|
|||||||
return !(lhs == rhs);
|
return !(lhs == rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const unique_ptr<MessageForwardInfo> &lhs, const unique_ptr<MessageForwardInfo> &rhs) {
|
||||||
|
if (lhs == nullptr) {
|
||||||
|
return rhs == nullptr;
|
||||||
|
}
|
||||||
|
return rhs != nullptr && *lhs == *rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const unique_ptr<MessageForwardInfo> &lhs, const unique_ptr<MessageForwardInfo> &rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder &operator<<(StringBuilder &string_builder, const MessageForwardInfo &forward_info) {
|
StringBuilder &operator<<(StringBuilder &string_builder, const MessageForwardInfo &forward_info) {
|
||||||
string_builder << "MessageForwardInfo[" << (forward_info.is_imported_ ? "imported " : "") << forward_info.origin_;
|
string_builder << "MessageForwardInfo[" << (forward_info.is_imported_ ? "imported " : "") << forward_info.origin_;
|
||||||
if (!forward_info.psa_type_.empty()) {
|
if (!forward_info.psa_type_.empty()) {
|
||||||
@ -105,4 +129,11 @@ StringBuilder &operator<<(StringBuilder &string_builder, const MessageForwardInf
|
|||||||
return string_builder << " at " << forward_info.date_ << ']';
|
return string_builder << " at " << forward_info.date_ << ']';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringBuilder &operator<<(StringBuilder &string_builder, const unique_ptr<MessageForwardInfo> &forward_info) {
|
||||||
|
if (forward_info == nullptr) {
|
||||||
|
return string_builder << "[null]";
|
||||||
|
}
|
||||||
|
return string_builder << *forward_info;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -60,6 +60,8 @@ struct MessageForwardInfo {
|
|||||||
|
|
||||||
void add_min_channel_ids(vector<ChannelId> &channel_ids) const;
|
void add_min_channel_ids(vector<ChannelId> &channel_ids) const;
|
||||||
|
|
||||||
|
static bool need_change_warning(const MessageForwardInfo *lhs, const MessageForwardInfo *rhs, MessageId message_id);
|
||||||
|
|
||||||
int32 get_origin_date() const {
|
int32 get_origin_date() const {
|
||||||
return date_;
|
return date_;
|
||||||
}
|
}
|
||||||
@ -91,6 +93,12 @@ bool operator==(const MessageForwardInfo &lhs, const MessageForwardInfo &rhs);
|
|||||||
|
|
||||||
bool operator!=(const MessageForwardInfo &lhs, const MessageForwardInfo &rhs);
|
bool operator!=(const MessageForwardInfo &lhs, const MessageForwardInfo &rhs);
|
||||||
|
|
||||||
|
bool operator==(const unique_ptr<MessageForwardInfo> &lhs, const unique_ptr<MessageForwardInfo> &rhs);
|
||||||
|
|
||||||
|
bool operator!=(const unique_ptr<MessageForwardInfo> &lhs, const unique_ptr<MessageForwardInfo> &rhs);
|
||||||
|
|
||||||
StringBuilder &operator<<(StringBuilder &string_builder, const MessageForwardInfo &forward_info);
|
StringBuilder &operator<<(StringBuilder &string_builder, const MessageForwardInfo &forward_info);
|
||||||
|
|
||||||
|
StringBuilder &operator<<(StringBuilder &string_builder, const unique_ptr<MessageForwardInfo> &forward_info);
|
||||||
|
|
||||||
} // namespace td
|
} // namespace td
|
||||||
|
@ -33087,57 +33087,21 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
|
|||||||
old_message->sender_dialog_id = new_message->sender_dialog_id;
|
old_message->sender_dialog_id = new_message->sender_dialog_id;
|
||||||
need_send_update = true;
|
need_send_update = true;
|
||||||
}
|
}
|
||||||
if (old_message->forward_info == nullptr) {
|
if (old_message->forward_info != new_message->forward_info) {
|
||||||
if (new_message->forward_info != nullptr) {
|
if (!replace_legacy && is_new_available &&
|
||||||
if (!replace_legacy) {
|
MessageForwardInfo::need_change_warning(old_message->forward_info.get(), new_message->forward_info.get(),
|
||||||
LOG(ERROR) << message_id << " in " << dialog_id << " has received forward info " << *new_message->forward_info
|
message_id)) {
|
||||||
<< ", really forwarded from " << old_message->real_forward_from_message_id << " in "
|
|
||||||
<< old_message->real_forward_from_dialog_id << ", message content type is " << old_content_type
|
|
||||||
<< '/' << new_content_type;
|
|
||||||
} else {
|
|
||||||
LOG(DEBUG) << "Message forward has changed to " << *new_message->forward_info;
|
|
||||||
}
|
|
||||||
old_message->forward_info = std::move(new_message->forward_info);
|
|
||||||
need_send_update = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (new_message->forward_info != nullptr) {
|
|
||||||
if (*old_message->forward_info != *new_message->forward_info) {
|
|
||||||
bool need_warning = [&] {
|
|
||||||
if (replace_legacy) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (old_message->forward_info->is_imported() || new_message->forward_info->is_imported()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!is_scheduled && !message_id.is_yet_unsent()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// yet unsent or scheduled messages can change sender name or author signature when being sent
|
|
||||||
return !old_message->forward_info->origin_.has_sender_signature() &&
|
|
||||||
!new_message->forward_info->origin_.has_sender_signature();
|
|
||||||
}();
|
|
||||||
if (need_warning) {
|
|
||||||
LOG(ERROR) << message_id << " in " << dialog_id << " has changed forward info from "
|
|
||||||
<< *old_message->forward_info << " to " << *new_message->forward_info << ", really forwarded from "
|
|
||||||
<< old_message->real_forward_from_message_id << " in " << old_message->real_forward_from_dialog_id
|
|
||||||
<< ", message content type is " << old_content_type << '/' << new_content_type;
|
|
||||||
} else {
|
|
||||||
LOG(DEBUG) << "Message forward info has changed from " << *old_message->forward_info << " to "
|
|
||||||
<< *new_message->forward_info;
|
|
||||||
}
|
|
||||||
old_message->forward_info = std::move(new_message->forward_info);
|
|
||||||
need_send_update = true;
|
|
||||||
}
|
|
||||||
} else if (is_new_available) {
|
|
||||||
LOG(ERROR) << message_id << " in " << dialog_id << " sent by " << old_message->sender_user_id << "/"
|
LOG(ERROR) << message_id << " in " << dialog_id << " sent by " << old_message->sender_user_id << "/"
|
||||||
<< old_message->sender_dialog_id << " has lost forward info " << *old_message->forward_info
|
<< old_message->sender_dialog_id << " has changed forward info from " << old_message->forward_info
|
||||||
<< ", really forwarded from " << old_message->real_forward_from_message_id << " in "
|
<< " to " << new_message->forward_info << ", really forwarded from "
|
||||||
<< old_message->real_forward_from_dialog_id << ", message content type is " << old_content_type << '/'
|
<< old_message->real_forward_from_message_id << " in " << old_message->real_forward_from_dialog_id
|
||||||
<< new_content_type;
|
<< ", message content type is " << old_content_type << '/' << new_content_type;
|
||||||
old_message->forward_info = nullptr;
|
} else {
|
||||||
need_send_update = true;
|
LOG(DEBUG) << "Message forward info has changed from " << old_message->forward_info << " to "
|
||||||
|
<< new_message->forward_info;
|
||||||
}
|
}
|
||||||
|
old_message->forward_info = std::move(new_message->forward_info);
|
||||||
|
need_send_update = true;
|
||||||
}
|
}
|
||||||
if (old_message->had_forward_info != new_message->had_forward_info) {
|
if (old_message->had_forward_info != new_message->had_forward_info) {
|
||||||
LOG(DEBUG) << "Message had_forward_info has changed from " << old_message->had_forward_info << " to "
|
LOG(DEBUG) << "Message had_forward_info has changed from " << old_message->had_forward_info << " to "
|
||||||
|
Loading…
Reference in New Issue
Block a user