From b7490e626ba1ee56e7752b92b8a48da4f098106d Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 28 Apr 2019 17:07:27 +0300 Subject: [PATCH] Add consistency checks for message deletion. GitOrigin-RevId: 8d37c28f2bbf6c12821437a3670e64a03d841495 --- td/telegram/MessagesManager.cpp | 18 ++++++++++++++++-- td/telegram/MessagesManager.h | 4 +++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 7d02ffd41..98863cd38 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -11097,10 +11097,17 @@ unique_ptr MessagesManager::do_delete_message(Dialog * } const Message *m = v->get(); + CHECK(m->message_id == message_id); + if (only_from_memory && !can_unload_message(d, m)) { return nullptr; } + LOG_CHECK(!d->being_deleted_message_id.is_valid()) << d->being_deleted_message_id << " " << message_id << " " + << d->debug_being_deleted_message_id_source << " " << source; + d->being_deleted_message_id = message_id; + d->debug_being_deleted_message_id_source = source; + if (is_debug_message_op_enabled()) { d->debug_message_op.emplace_back(Dialog::MessageOp::Delete, m->message_id, m->content->get_type(), false, m->have_previous, m->have_next, source); @@ -11227,6 +11234,8 @@ unique_ptr MessagesManager::do_delete_message(Dialog * unique_ptr left = std::move(result->left); unique_ptr right = std::move(result->right); + LOG_CHECK(result->message_id == message_id) << result->message_id << " " << message_id << " " << source; + while (left != nullptr || right != nullptr) { if (left == nullptr || (right != nullptr && right->random_y > left->random_y)) { *v = std::move(right); @@ -11240,6 +11249,9 @@ unique_ptr MessagesManager::do_delete_message(Dialog * } CHECK(*v == nullptr); + d->being_deleted_message_id = MessageId(); + d->debug_being_deleted_message_id_source = ""; + if (!only_from_memory) { if (message_id.is_yet_unsent()) { cancel_send_message_query(d->dialog_id, result); @@ -22525,7 +22537,9 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq << d->dialog_id << " " << d->being_added_message_id << " " << message_id << " " << *need_update << " " << d->debug_being_added_need_update << " " << d->pinned_message_notification_message_id << " " << preloaded_pinned_message_id << " " << d->debug_preloaded_pinned_message_id << " " - << d->debug_added_pinned_message_id << " " << d->debug_add_message_to_dialog_fail_reason_ << " " << source; + << d->debug_added_pinned_message_id << " " << d->debug_add_message_to_dialog_fail_reason << " " << source; + LOG_CHECK(!d->being_deleted_message_id.is_valid()) << d->being_deleted_message_id << " " << message_id << " " + << d->debug_being_deleted_message_id_source << " " << source; d->being_added_message_id = message_id; d->being_updated_last_new_message_id = d->last_new_message_id; @@ -22533,7 +22547,7 @@ MessagesManager::Message *MessagesManager::add_message_to_dialog(Dialog *d, uniq d->debug_being_added_need_update = *need_update; d->debug_preloaded_pinned_message_id = preloaded_pinned_message_id; d->debug_added_pinned_message_id = added_pinned_message_id; - d->debug_add_message_to_dialog_fail_reason_ = add_error_reason; + d->debug_add_message_to_dialog_fail_reason = add_error_reason; if (d->new_secret_chat_notification_id.is_valid()) { remove_new_secret_chat_notification(d, true); diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 68e270b3c..2cf764eba 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -974,10 +974,12 @@ class MessagesManager : public Actor { MessageId being_added_message_id; MessageId being_updated_last_new_message_id; MessageId being_updated_last_database_message_id; + MessageId being_deleted_message_id; + const char *debug_being_deleted_message_id_source = ""; bool debug_being_added_need_update = false; // TODO remove MessageId debug_preloaded_pinned_message_id; // TODO remove MessageId debug_added_pinned_message_id; // TODO remove - const char *debug_add_message_to_dialog_fail_reason_ = ""; + const char *debug_add_message_to_dialog_fail_reason = ""; NotificationGroupInfo message_notification_group; NotificationGroupInfo mention_notification_group;