From fd5b5d6e55b6b63072f8adefa57bcb00c386cb26 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 15 Feb 2019 19:54:18 +0300 Subject: [PATCH] Fix cancelling upload file for yet unsent messages. GitOrigin-RevId: e525b421c7cf1cd98923215dba23966496f2e36c --- td/telegram/MessagesManager.cpp | 19 ++++++++++++------- td/telegram/MessagesManager.h | 2 ++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index b12c24c65..a2bed2832 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -6277,8 +6277,8 @@ void MessagesManager::on_load_secret_thumbnail(FileId thumbnail_file_id, BufferS if (m == nullptr) { // message has already been deleted by the user, do not need to send it // cancel file upload of the main file to allow next upload with the same file to succeed - td_->file_manager_->cancel_upload(file_id); LOG(INFO) << "Message with a media has already been deleted"; + cancel_upload_file(file_id); return; } CHECK(m->message_id.is_yet_unsent()); @@ -15005,18 +15005,23 @@ vector MessagesManager::get_message_file_ids(const Message *message) con void MessagesManager::cancel_upload_message_content_files(const MessageContent *content) { auto file_id = get_message_content_file_id(content); - // always cancel file upload, it is a no-op in the worst case + // always cancel file upload, it should be a no-op in the worst case if (being_uploaded_files_.erase(file_id) || file_id.is_valid()) { - LOG(INFO) << "Cancel upload file " << file_id; - td_->file_manager_->cancel_upload(file_id); + cancel_upload_file(file_id); } file_id = get_message_content_thumbnail_file_id(content, td_); if (being_uploaded_thumbnails_.erase(file_id) || file_id.is_valid()) { - LOG(INFO) << "Cancel upload thumbnail file " << file_id; - td_->file_manager_->cancel_upload(file_id); + cancel_upload_file(file_id); } } +void MessagesManager::cancel_upload_file(FileId file_id) { + // send the request later so they doesn't interfere with other actions + // for example merge, supposed to happen soon, can auto-cancel the upload + LOG(WARNING) << "Cancel upload of file " << file_id; + send_closure_later(G()->file_manager(), &FileManager::cancel_upload, file_id); +} + void MessagesManager::cancel_send_message_query(DialogId dialog_id, unique_ptr &m) { CHECK(m != nullptr); CHECK(m->content != nullptr); @@ -22431,7 +22436,7 @@ bool MessagesManager::update_message_content(DialogId dialog_id, Message *old_me if (need_finish_upload) { // the file is likely to be already merged with a server file, but if not we need to // cancel file upload of the main file to allow next upload with the same file to succeed - td_->file_manager_->cancel_upload(old_file_id); + cancel_upload_file(old_file_id); } if (is_content_changed || need_update) { diff --git a/td/telegram/MessagesManager.h b/td/telegram/MessagesManager.h index 83b70a08a..1a7fc40fb 100644 --- a/td/telegram/MessagesManager.h +++ b/td/telegram/MessagesManager.h @@ -1802,6 +1802,8 @@ class MessagesManager : public Actor { void cancel_upload_message_content_files(const MessageContent *content); + static void cancel_upload_file(FileId file_id); + void cancel_send_message_query(DialogId dialog_id, unique_ptr &m); static int32 get_message_flags(const Message *m);