From 53d694a01c994f29c138637c7ba0fe56fd946b60 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 4 Jul 2020 12:00:14 +0300 Subject: [PATCH] Fix get_actor_unsafe usages. GitOrigin-RevId: f39aa2d0a2083842698337bb34457826c1951be6 --- td/telegram/FileReferenceManager.cpp | 19 ++++--------------- td/telegram/files/FileManager.cpp | 15 +++++++++++++++ td/telegram/files/FileManager.h | 3 +++ td/telegram/files/FileStatsWorker.cpp | 1 + 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/td/telegram/FileReferenceManager.cpp b/td/telegram/FileReferenceManager.cpp index 63e9a479c..4d8e4ba73 100644 --- a/td/telegram/FileReferenceManager.cpp +++ b/td/telegram/FileReferenceManager.cpp @@ -14,6 +14,7 @@ #include "td/telegram/MessagesManager.h" #include "td/telegram/StickerSetId.h" #include "td/telegram/StickersManager.h" +#include "td/telegram/Td.h" #include "td/telegram/WebPagesManager.h" #include "td/utils/common.h" @@ -232,20 +233,8 @@ void FileReferenceManager::send_query(Destination dest, FileSourceId file_source std::move(status), 0); }); - send_lambda(file_manager, [file_manager, dest, result = std::move(result), file_source_id, - new_promise = std::move(new_promise)]() mutable { - auto view = file_manager.get_actor_unsafe()->get_file_view(dest.node_id); - CHECK(!view.empty()); - if (result.is_ok() && - (!view.has_active_upload_remote_location() || !view.has_active_download_remote_location())) { - result = Status::Error("No active remote location"); - } - if (result.is_error() && result.error().code() != 429 && result.error().code() < 500) { - VLOG(file_references) << "Invalid " << file_source_id << " " << result.error(); - file_manager.get_actor_unsafe()->remove_file_source(dest.node_id, file_source_id); - } - new_promise.set_result(std::move(result)); - }); + send_closure(file_manager, &FileManager::on_file_reference_repaired, dest.node_id, file_source_id, + std::move(result), std::move(new_promise)); }); auto index = static_cast(file_source_id.get()) - 1; CHECK(index < file_sources_.size()); @@ -325,7 +314,7 @@ FileReferenceManager::Destination FileReferenceManager::on_query_result(Destinat } void FileReferenceManager::repair_file_reference(NodeId node_id, Promise<> promise) { - auto main_file_id = G()->file_manager().get_actor_unsafe()->get_file_view(node_id).file_id(); + auto main_file_id = G()->td().get_actor_unsafe()->file_manager_->get_file_view(node_id).file_id(); VLOG(file_references) << "Repair file reference for file " << node_id << "/" << main_file_id; node_id = main_file_id; auto &node = nodes_[node_id]; diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 5f54a95c9..b2a4197ac 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -1670,6 +1670,21 @@ void FileManager::change_files_source(FileSourceId file_source_id, const vector< } } +void FileManager::on_file_reference_repaired(FileId file_id, FileSourceId file_source_id, Result &&result, + Promise &&promise) { + auto file_view = get_file_view(file_id); + CHECK(!file_view.empty()); + if (result.is_ok() && + (!file_view.has_active_upload_remote_location() || !file_view.has_active_download_remote_location())) { + result = Status::Error("No active remote location"); + } + if (result.is_error() && result.error().code() != 429 && result.error().code() < 500) { + VLOG(file_references) << "Invalid " << file_source_id << " " << result.error(); + remove_file_source(file_id, file_source_id); + } + promise.set_result(std::move(result)); +} + std::unordered_set FileManager::get_main_file_ids(const vector &file_ids) { std::unordered_set result; for (auto file_id : file_ids) { diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index 25b2b2e58..ee1f6dca2 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -419,6 +419,9 @@ class FileManager : public FileLoadManager::Callback { void change_files_source(FileSourceId file_source_id, const vector &old_file_ids, const vector &new_file_ids); + void on_file_reference_repaired(FileId file_id, FileSourceId file_source_id, Result &&result, + Promise &&promise); + bool set_encryption_key(FileId file_id, FileEncryptionKey key); bool set_content(FileId file_id, BufferSlice bytes); diff --git a/td/telegram/files/FileStatsWorker.cpp b/td/telegram/files/FileStatsWorker.cpp index 5c559adb8..5b84b31b1 100644 --- a/td/telegram/files/FileStatsWorker.cpp +++ b/td/telegram/files/FileStatsWorker.cpp @@ -31,6 +31,7 @@ #include #include +#include namespace td { namespace {