Replace all message reply-related fields simultaneously.
This commit is contained in:
parent
6f082a40d2
commit
bc618b855e
@ -35614,18 +35614,24 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool is_top_thread_message_id_changed =
|
||||||
|
old_message->top_thread_message_id != new_message->top_thread_message_id;
|
||||||
|
const bool is_is_topic_message_changed = old_message->is_topic_message != new_message->is_topic_message;
|
||||||
|
if (is_new_available && (old_message->reply_to_message_id != new_message->reply_to_message_id ||
|
||||||
|
old_message->reply_in_dialog_id != new_message->reply_in_dialog_id ||
|
||||||
|
is_top_thread_message_id_changed || is_is_topic_message_changed)) {
|
||||||
|
if (!replace_legacy) {
|
||||||
if (old_message->reply_to_message_id != new_message->reply_to_message_id) {
|
if (old_message->reply_to_message_id != new_message->reply_to_message_id) {
|
||||||
// Can't check "&& get_message_force(d, old_message->reply_to_message_id, "update_message") == nullptr", because it
|
LOG(INFO) << "Update replied message of " << FullMessageId{dialog_id, message_id} << " from "
|
||||||
// can change message tree and invalidate reference to old_message
|
<< old_message->reply_to_message_id << " to " << new_message->reply_to_message_id;
|
||||||
if (new_message->reply_to_message_id == MessageId() || replace_legacy) {
|
if (message_id.is_yet_unsent() && new_message->reply_to_message_id == MessageId() &&
|
||||||
set_message_reply(d, old_message, MessageId(), is_message_in_dialog);
|
old_message->reply_in_dialog_id == DialogId() && is_deleted_message(d, old_message->reply_to_message_id) &&
|
||||||
need_send_update = true;
|
!is_message_in_dialog) {
|
||||||
} else if (is_new_available) {
|
// reply to a deleted message
|
||||||
if (message_id.is_yet_unsent() && old_message->reply_to_message_id == MessageId() &&
|
} else if (message_id.is_yet_unsent() && old_message->reply_to_message_id == MessageId() &&
|
||||||
new_message->reply_in_dialog_id == DialogId() && is_deleted_message(d, new_message->reply_to_message_id) &&
|
new_message->reply_in_dialog_id == DialogId() &&
|
||||||
get_message(d, new_message->reply_to_message_id) == nullptr && !is_message_in_dialog) {
|
is_deleted_message(d, new_message->reply_to_message_id) && !is_message_in_dialog) {
|
||||||
set_message_reply(d, old_message, new_message->reply_to_message_id, is_message_in_dialog);
|
// reply to a deleted message
|
||||||
need_send_update = true;
|
|
||||||
} else if (old_message->reply_to_message_id.is_valid_scheduled() &&
|
} else if (old_message->reply_to_message_id.is_valid_scheduled() &&
|
||||||
old_message->reply_to_message_id.is_scheduled_server() &&
|
old_message->reply_to_message_id.is_scheduled_server() &&
|
||||||
new_message->reply_to_message_id.is_valid_scheduled() &&
|
new_message->reply_to_message_id.is_valid_scheduled() &&
|
||||||
@ -35633,51 +35639,74 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
|
|||||||
old_message->reply_to_message_id.get_scheduled_server_message_id() ==
|
old_message->reply_to_message_id.get_scheduled_server_message_id() ==
|
||||||
new_message->reply_to_message_id.get_scheduled_server_message_id() &&
|
new_message->reply_to_message_id.get_scheduled_server_message_id() &&
|
||||||
new_message->reply_in_dialog_id == DialogId()) {
|
new_message->reply_in_dialog_id == DialogId()) {
|
||||||
// schedule date has changed
|
// schedule date change
|
||||||
set_message_reply(d, old_message, new_message->reply_to_message_id, is_message_in_dialog);
|
} else if (message_id.is_yet_unsent() &&
|
||||||
} else if (message_id.is_yet_unsent() && old_message->top_thread_message_id == new_message->reply_to_message_id &&
|
old_message->top_thread_message_id == new_message->reply_to_message_id &&
|
||||||
new_message->reply_in_dialog_id == DialogId()) {
|
new_message->reply_in_dialog_id == DialogId()) {
|
||||||
set_message_reply(d, old_message, new_message->reply_to_message_id, is_message_in_dialog);
|
// move of reply to the top thread message
|
||||||
need_send_update = true;
|
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << message_id << " in " << dialog_id << " has changed replied message from "
|
LOG(ERROR) << message_id << " in " << dialog_id << " has changed replied message from "
|
||||||
<< old_message->reply_to_message_id << " to " << new_message->reply_to_message_id
|
<< old_message->reply_to_message_id << " to " << new_message->reply_to_message_id
|
||||||
<< ", message content type is " << old_content_type << '/' << new_content_type;
|
<< ", message content type is " << old_content_type << '/' << new_content_type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (old_message->reply_in_dialog_id != new_message->reply_in_dialog_id) {
|
if (old_message->reply_in_dialog_id != new_message->reply_in_dialog_id) {
|
||||||
if (new_message->reply_in_dialog_id == DialogId() || replace_legacy) {
|
|
||||||
LOG(DEBUG) << "Drop message reply_in_dialog_id";
|
|
||||||
old_message->reply_in_dialog_id = DialogId();
|
|
||||||
need_send_update = true;
|
|
||||||
} else if (is_new_available && old_message->reply_in_dialog_id.is_valid()) {
|
|
||||||
LOG(ERROR) << message_id << " in " << dialog_id << " has changed replied message chat from "
|
LOG(ERROR) << message_id << " in " << dialog_id << " has changed replied message chat from "
|
||||||
<< old_message->reply_in_dialog_id << " to " << new_message->reply_in_dialog_id
|
<< old_message->reply_in_dialog_id << " to " << new_message->reply_in_dialog_id
|
||||||
<< ", message content type is " << old_content_type << '/' << new_content_type;
|
<< ", message content type is " << old_content_type << '/' << new_content_type;
|
||||||
}
|
}
|
||||||
}
|
if (is_top_thread_message_id_changed) {
|
||||||
if (old_message->top_thread_message_id != new_message->top_thread_message_id) {
|
if ((new_message->top_thread_message_id != MessageId() && old_message->top_thread_message_id != MessageId()) ||
|
||||||
if ((new_message->top_thread_message_id == MessageId() || old_message->top_thread_message_id == MessageId()) &&
|
is_message_in_dialog) {
|
||||||
(!is_message_in_dialog || replace_legacy)) {
|
|
||||||
LOG(DEBUG) << "Change message thread from " << old_message->top_thread_message_id << " to "
|
|
||||||
<< new_message->top_thread_message_id;
|
|
||||||
if (is_message_in_dialog && old_message->is_topic_message) {
|
|
||||||
if (old_message->top_thread_message_id != MessageId()) {
|
|
||||||
td_->forum_topic_manager_->on_topic_message_count_changed(dialog_id, old_message->top_thread_message_id, -1);
|
|
||||||
}
|
|
||||||
if (new_message->top_thread_message_id != MessageId()) {
|
|
||||||
td_->forum_topic_manager_->on_topic_message_count_changed(dialog_id, new_message->top_thread_message_id, +1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
old_message->top_thread_message_id = new_message->top_thread_message_id;
|
|
||||||
need_send_update = true;
|
|
||||||
} else if (is_new_available) {
|
|
||||||
LOG(ERROR) << message_id << " in " << dialog_id << " has changed message thread from "
|
LOG(ERROR) << message_id << " in " << dialog_id << " has changed message thread from "
|
||||||
<< old_message->top_thread_message_id << " to " << new_message->top_thread_message_id
|
<< old_message->top_thread_message_id << " to " << new_message->top_thread_message_id
|
||||||
<< ", message content type is " << old_content_type << '/' << new_content_type;
|
<< ", message content type is " << old_content_type << '/' << new_content_type;
|
||||||
|
} else {
|
||||||
|
LOG(INFO) << "Update message thread of " << FullMessageId{dialog_id, message_id} << " from "
|
||||||
|
<< old_message->top_thread_message_id << " to " << new_message->top_thread_message_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (is_is_topic_message_changed) {
|
||||||
|
if (!message_id.is_yet_unsent()) {
|
||||||
|
LOG(ERROR) << message_id << " in " << dialog_id << " has changed is_topic_message to "
|
||||||
|
<< new_message->is_topic_message;
|
||||||
|
} else {
|
||||||
|
LOG(INFO) << "Update is_topic_message of " << FullMessageId{dialog_id, message_id} << " from "
|
||||||
|
<< old_message->is_topic_message << " to " << new_message->is_topic_message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((is_top_thread_message_id_changed || is_is_topic_message_changed) && is_message_in_dialog &&
|
||||||
|
old_message->is_topic_message && old_message->top_thread_message_id != MessageId()) {
|
||||||
|
td_->forum_topic_manager_->on_topic_message_count_changed(dialog_id, old_message->top_thread_message_id, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_message_in_dialog) {
|
||||||
|
unregister_message_reply(d->dialog_id, old_message);
|
||||||
|
}
|
||||||
|
old_message->reply_in_dialog_id = new_message->reply_in_dialog_id;
|
||||||
|
old_message->reply_to_message_id = new_message->reply_to_message_id;
|
||||||
|
old_message->top_thread_message_id = new_message->top_thread_message_id;
|
||||||
|
old_message->reply_to_random_id = 0;
|
||||||
|
if (old_message->reply_in_dialog_id == DialogId() && old_message->reply_to_message_id != MessageId() &&
|
||||||
|
old_message->message_id.is_yet_unsent() &&
|
||||||
|
(dialog_id.get_type() == DialogType::SecretChat || old_message->reply_to_message_id.is_yet_unsent())) {
|
||||||
|
auto *replied_m = get_message(d, old_message->reply_to_message_id);
|
||||||
|
if (replied_m != nullptr) {
|
||||||
|
old_message->reply_to_random_id = replied_m->random_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (is_message_in_dialog) {
|
||||||
|
register_message_reply(d->dialog_id, old_message);
|
||||||
|
}
|
||||||
|
update_message_max_reply_media_timestamp(d, old_message, is_message_in_dialog);
|
||||||
|
if ((is_top_thread_message_id_changed || is_is_topic_message_changed) && is_message_in_dialog &&
|
||||||
|
old_message->is_topic_message && old_message->top_thread_message_id != MessageId()) {
|
||||||
|
td_->forum_topic_manager_->on_topic_message_count_changed(dialog_id, old_message->top_thread_message_id, +1);
|
||||||
|
}
|
||||||
|
need_send_update = true;
|
||||||
|
}
|
||||||
if (old_message->via_bot_user_id != new_message->via_bot_user_id) {
|
if (old_message->via_bot_user_id != new_message->via_bot_user_id) {
|
||||||
if ((!message_id.is_yet_unsent() || old_message->via_bot_user_id.is_valid()) && is_new_available &&
|
if ((!message_id.is_yet_unsent() || old_message->via_bot_user_id.is_valid()) && is_new_available &&
|
||||||
!replace_legacy) {
|
!replace_legacy) {
|
||||||
@ -35715,21 +35744,6 @@ bool MessagesManager::update_message(Dialog *d, Message *old_message, unique_ptr
|
|||||||
<< message_id << " in " << dialog_id << " has changed is_channel_post from " << old_message->is_channel_post
|
<< message_id << " in " << dialog_id << " has changed is_channel_post from " << old_message->is_channel_post
|
||||||
<< " to " << new_message->is_channel_post << ", message content type is " << old_content_type << '/'
|
<< " to " << new_message->is_channel_post << ", message content type is " << old_content_type << '/'
|
||||||
<< new_content_type;
|
<< new_content_type;
|
||||||
if (!old_message->top_thread_message_id.is_valid()) {
|
|
||||||
new_message->is_topic_message = false;
|
|
||||||
}
|
|
||||||
if (old_message->is_topic_message != new_message->is_topic_message &&
|
|
||||||
old_message->top_thread_message_id == new_message->top_thread_message_id) {
|
|
||||||
if (is_message_in_dialog) {
|
|
||||||
td_->forum_topic_manager_->on_topic_message_count_changed(
|
|
||||||
dialog_id, old_message->top_thread_message_id,
|
|
||||||
static_cast<int>(new_message->is_topic_message) - static_cast<int>(old_message->is_topic_message));
|
|
||||||
}
|
|
||||||
LOG_IF(ERROR, !message_id.is_yet_unsent() && !replace_legacy)
|
|
||||||
<< message_id << " in " << dialog_id << " has changed is_topic_message to " << new_message->is_topic_message;
|
|
||||||
old_message->is_topic_message = new_message->is_topic_message;
|
|
||||||
need_send_update = true;
|
|
||||||
}
|
|
||||||
if (old_message->contains_mention != new_message->contains_mention) {
|
if (old_message->contains_mention != new_message->contains_mention) {
|
||||||
if (old_message->edit_date == 0 && is_new_available && old_content_type != MessageContentType::PinMessage &&
|
if (old_message->edit_date == 0 && is_new_available && old_content_type != MessageContentType::PinMessage &&
|
||||||
old_content_type != MessageContentType::ExpiredPhoto && old_content_type != MessageContentType::ExpiredVideo &&
|
old_content_type != MessageContentType::ExpiredPhoto && old_content_type != MessageContentType::ExpiredVideo &&
|
||||||
|
Loading…
Reference in New Issue
Block a user