diff --git a/td/telegram/files/FileDownloader.h b/td/telegram/files/FileDownloader.h index 05276151e..62ee6419b 100644 --- a/td/telegram/files/FileDownloader.h +++ b/td/telegram/files/FileDownloader.h @@ -137,9 +137,6 @@ class FileDownloader final : public FileLoaderActor { void update_resources(const ResourceState &other) final; - void update_local_file_location(const LocalFileLocation &local) final { - } - void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) final; void start_up() final; diff --git a/td/telegram/files/FileLoaderActor.h b/td/telegram/files/FileLoaderActor.h index e351a6213..898a7ed13 100644 --- a/td/telegram/files/FileLoaderActor.h +++ b/td/telegram/files/FileLoaderActor.h @@ -23,8 +23,6 @@ class FileLoaderActor : public NetQueryCallback { virtual void update_resources(const ResourceState &other) = 0; // TODO: existence of these two functions is a dirty hack. Refactoring is highly appreciated - virtual void update_local_file_location(const LocalFileLocation &local) { - } virtual void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) { } }; diff --git a/td/telegram/files/FileUploadManager.cpp b/td/telegram/files/FileUploadManager.cpp index b393aa227..659abea77 100644 --- a/td/telegram/files/FileUploadManager.cpp +++ b/td/telegram/files/FileUploadManager.cpp @@ -36,10 +36,10 @@ void FileUploadManager::upload(QueryId query_id, const LocalFileLocation &local_ CHECK(node); node->query_id_ = query_id; auto callback = make_unique(actor_shared(this, node_id)); - node->loader_ = create_actor("Uploader", local_location, remote_location, expected_size, encryption_key, - std::move(bad_parts), std::move(callback)); + node->uploader_ = create_actor("Uploader", local_location, remote_location, expected_size, + encryption_key, std::move(bad_parts), std::move(callback)); send_closure(upload_resource_manager_, &ResourceManager::register_worker, - ActorShared(node->loader_.get(), static_cast(-1)), priority); + ActorShared(node->uploader_.get(), static_cast(-1)), priority); bool is_inserted = query_id_to_node_id_.emplace(query_id, node_id).second; CHECK(is_inserted); } @@ -54,9 +54,9 @@ void FileUploadManager::upload_by_hash(QueryId query_id, const FullLocalFileLoca CHECK(node); node->query_id_ = query_id; auto callback = make_unique(actor_shared(this, node_id)); - node->loader_ = create_actor("HashUploader", local_location, size, std::move(callback)); + node->hash_uploader_ = create_actor("HashUploader", local_location, size, std::move(callback)); send_closure(upload_resource_manager_, &ResourceManager::register_worker, - ActorShared(node->loader_.get(), static_cast(-1)), priority); + ActorShared(node->hash_uploader_.get(), static_cast(-1)), priority); bool is_inserted = query_id_to_node_id_.emplace(query_id, node_id).second; CHECK(is_inserted); } @@ -73,7 +73,11 @@ void FileUploadManager::update_priority(QueryId query_id, int8 priority) { if (node == nullptr) { return; } - send_closure(node->loader_, &FileLoaderActor::update_priority, priority); + if (!node->uploader_.empty()) { + send_closure(node->uploader_, &FileLoaderActor::update_priority, priority); + } else { + send_closure(node->hash_uploader_, &FileLoaderActor::update_priority, priority); + } } void FileUploadManager::cancel(QueryId query_id) { @@ -96,14 +100,17 @@ void FileUploadManager::update_local_file_location(QueryId query_id, const Local return; } auto node = nodes_container_.get(it->second); - if (node == nullptr) { + if (node == nullptr || node->uploader_.empty()) { return; } - send_closure(node->loader_, &FileLoaderActor::update_local_file_location, local); + send_closure(node->uploader_, &FileUploader::update_local_file_location, local); } void FileUploadManager::hangup() { - nodes_container_.for_each([](auto query_id, auto &node) { node.loader_.reset(); }); + nodes_container_.for_each([](auto query_id, auto &node) { + node.uploader_.reset(); + node.hash_uploader_.reset(); + }); stop_flag_ = true; loop(); } diff --git a/td/telegram/files/FileUploadManager.h b/td/telegram/files/FileUploadManager.h index 339d69ce4..71cb8e278 100644 --- a/td/telegram/files/FileUploadManager.h +++ b/td/telegram/files/FileUploadManager.h @@ -53,7 +53,8 @@ class FileUploadManager final : public Actor { private: struct Node { QueryId query_id_; - ActorOwn loader_; + ActorOwn uploader_; + ActorOwn hash_uploader_; }; using NodeId = uint64; diff --git a/td/telegram/files/FileUploader.h b/td/telegram/files/FileUploader.h index 6385a216c..97e2ae8aa 100644 --- a/td/telegram/files/FileUploader.h +++ b/td/telegram/files/FileUploader.h @@ -48,7 +48,7 @@ class FileUploader final : public FileLoaderActor { void update_resources(const ResourceState &other) final; - void update_local_file_location(const LocalFileLocation &local) final; + void update_local_file_location(const LocalFileLocation &local); void update_downloaded_part(int64 offset, int64 limit, int64 max_resource_limit) { }