diff --git a/td/telegram/FileReferenceManager.cpp b/td/telegram/FileReferenceManager.cpp index d5785369c..94d801737 100644 --- a/td/telegram/FileReferenceManager.cpp +++ b/td/telegram/FileReferenceManager.cpp @@ -32,10 +32,17 @@ namespace td { int VERBOSITY_NAME(file_references) = VERBOSITY_NAME(INFO); +FileReferenceManager::FileReferenceManager(ActorShared<> parent) : parent_(std::move(parent)) { +} + FileReferenceManager::~FileReferenceManager() { Scheduler::instance()->destroy_on_scheduler(G()->get_gc_scheduler_id(), file_sources_); } +void FileReferenceManager::tear_down() { + parent_.reset(); +} + bool FileReferenceManager::is_file_reference_error(const Status &error) { return error.is_error() && error.code() == 400 && begins_with(error.message(), "FILE_REFERENCE_"); } diff --git a/td/telegram/FileReferenceManager.h b/td/telegram/FileReferenceManager.h index 99c60d84a..3cbd75529 100644 --- a/td/telegram/FileReferenceManager.h +++ b/td/telegram/FileReferenceManager.h @@ -36,7 +36,7 @@ extern int VERBOSITY_NAME(file_references); class FileReferenceManager final : public Actor { public: - FileReferenceManager() = default; + explicit FileReferenceManager(ActorShared<> parent); FileReferenceManager(const FileReferenceManager &) = delete; FileReferenceManager &operator=(const FileReferenceManager &) = delete; FileReferenceManager(FileReferenceManager &&) = delete; @@ -173,6 +173,8 @@ class FileReferenceManager final : public Actor { FlatHashMap nodes_; + ActorShared<> parent_; + void run_node(NodeId node); void send_query(Destination dest, FileSourceId file_source_id); Destination on_query_result(Destination dest, FileSourceId file_source_id, Status status, int32 sub = 0); @@ -181,6 +183,8 @@ class FileReferenceManager final : public Actor { FileSourceId add_file_source_id(T source, Slice source_str); FileSourceId get_current_file_source_id() const; + + void tear_down() override; }; } // namespace td diff --git a/td/telegram/SecureManager.cpp b/td/telegram/SecureManager.cpp index fea0e57b5..1ad17055a 100644 --- a/td/telegram/SecureManager.cpp +++ b/td/telegram/SecureManager.cpp @@ -489,6 +489,7 @@ void SetSecureValue::load_secret() { send_closure(actor_id, &SetSecureValue::on_secret, std::move(r_secret), true); })); } + void SetSecureValue::cancel_upload() { upload_generation_++; auto *file_manager = G()->td().get_actor_unsafe()->file_manager_.get(); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 29f560ebf..44b238a4a 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3939,7 +3939,7 @@ void Td::init_file_manager() { file_manager_->init_actor(); G()->set_file_manager(file_manager_actor_.get()); - file_reference_manager_ = make_unique(); + file_reference_manager_ = make_unique(create_reference()); file_reference_manager_actor_ = register_actor("FileReferenceManager", file_reference_manager_.get()); G()->set_file_reference_manager(file_reference_manager_actor_.get()); }