From 0b53ace8d01c116389ffef66a2f93fb0d320b13c Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 4 Apr 2021 22:59:56 +0300 Subject: [PATCH] Improve deletion of deleted being sent messages. --- td/telegram/MessagesManager.cpp | 36 ++++++++++++++++++++------------- td/telegram/MessagesManager.h | 2 +- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 608e6cea0..8fb41cb58 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -10458,13 +10458,25 @@ void MessagesManager::delete_messages(DialogId dialog_id, const vector old_message = delete_message(d, old_message_id, false, &need_update_dialog_pos, "add sent message"); if (old_message == nullptr) { - // message has already been deleted by the user or sent to inaccessible channel - // don't need to send update to the user, because the message has already been deleted - LOG(INFO) << "Delete already deleted sent " << new_message->message_id << " from server"; - delete_message_from_server(dialog_id, new_message->message_id, true); + delete_sent_message_from_server(dialog_id, new_message->message_id); being_readded_message_id_ = FullMessageId(); return FullMessageId(); } @@ -26961,6 +26970,7 @@ bool MessagesManager::on_update_message_id(int64 random_id, MessageId new_messag being_sent_messages_.erase(it); LOG(INFO) << "Save correspondence from " << new_message_id << " in " << dialog_id << " to " << old_message_id; + CHECK(old_message_id.is_yet_unsent()); update_message_ids_[FullMessageId(dialog_id, new_message_id)] = old_message_id; return true; } @@ -26985,6 +26995,7 @@ bool MessagesManager::on_update_scheduled_message_id(int64 random_id, ScheduledS being_sent_messages_.erase(it); LOG(INFO) << "Save correspondence from " << new_message_id << " in " << dialog_id << " to " << old_message_id; + CHECK(old_message_id.is_yet_unsent()); update_scheduled_message_ids_[dialog_id][new_message_id] = old_message_id; return true; } @@ -28771,10 +28782,7 @@ FullMessageId MessagesManager::on_send_message_success(int64 random_id, MessageI being_readded_message_id_ = {dialog_id, old_message_id}; unique_ptr sent_message = delete_message(d, old_message_id, false, &need_update_dialog_pos, source); if (sent_message == nullptr) { - // message has already been deleted by the user or sent to inaccessible channel - // don't need to send update to the user, because the message has already been deleted - LOG(INFO) << "Delete already deleted sent " << new_message_id << " from server"; - delete_message_from_server(dialog_id, new_message_id, true); + delete_sent_message_from_server(dialog_id, new_message_id); being_readded_message_id_ = FullMessageId(); return {}; } diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 8aacc9571..03dd95dc1 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1906,7 +1906,7 @@ class MessagesManager : public Actor { void do_delete_all_dialog_messages(Dialog *d, unique_ptr &message, bool is_permanently_deleted, vector &deleted_message_ids); - void delete_message_from_server(DialogId dialog_id, MessageId message_ids, bool revoke); + void delete_sent_message_from_server(DialogId dialog_id, MessageId message_id); void delete_messages_from_server(DialogId dialog_id, vector message_ids, bool revoke, uint64 log_event_id, Promise &&promise);