From ec19eaad650823c6840d780caef8f18ac0b6db0d Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 23 Jul 2022 17:01:27 +0300 Subject: [PATCH] Call FileReferenceManager::get_file_search_text through DownloadManagerCallback. --- td/telegram/DownloadManager.cpp | 15 +++++++-------- td/telegram/DownloadManager.h | 3 ++- td/telegram/DownloadManagerCallback.cpp | 6 ++++++ td/telegram/DownloadManagerCallback.h | 4 +++- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/td/telegram/DownloadManager.cpp b/td/telegram/DownloadManager.cpp index 21fd17cdf..ca60fa40e 100644 --- a/td/telegram/DownloadManager.cpp +++ b/td/telegram/DownloadManager.cpp @@ -6,7 +6,6 @@ // #include "td/telegram/DownloadManager.h" -#include "td/telegram/FileReferenceManager.h" #include "td/telegram/files/FileId.hpp" #include "td/telegram/files/FileSourceId.hpp" #include "td/telegram/Global.h" @@ -534,13 +533,13 @@ class DownloadManagerImpl final : public DownloadManager { void prepare_hints() { for (auto &it : files_) { const auto &file_info = *it.second; - send_closure(G()->file_reference_manager(), &FileReferenceManager::get_file_search_text, file_info.file_source_id, - callback_->get_file_view(file_info.file_id).get_unique_file_id(), - [actor_id = actor_id(this), promise = load_search_text_multipromise_.get_promise(), - download_id = it.first](Result r_search_text) mutable { - send_closure(actor_id, &DownloadManagerImpl::add_download_to_hints, download_id, - std::move(r_search_text), std::move(promise)); - }); + auto promise = + PromiseCreator::lambda([actor_id = actor_id(this), promise = load_search_text_multipromise_.get_promise(), + download_id = it.first](Result r_search_text) mutable { + send_closure(actor_id, &DownloadManagerImpl::add_download_to_hints, download_id, std::move(r_search_text), + std::move(promise)); + }); + callback_->get_file_search_text(file_info.file_id, file_info.file_source_id, std::move(promise)); } } diff --git a/td/telegram/DownloadManager.h b/td/telegram/DownloadManager.h index 10e4c1c04..b34d20ae2 100644 --- a/td/telegram/DownloadManager.h +++ b/td/telegram/DownloadManager.h @@ -73,7 +73,8 @@ class DownloadManager : public Actor { virtual void delete_file(FileId file_id) = 0; virtual FileId dup_file_id(FileId file_id) = 0; - virtual FileView get_file_view(FileId file_id) = 0; + virtual void get_file_search_text(FileId file_id, FileSourceId file_source_id, Promise &&promise) = 0; + virtual FileView get_sync_file_view(FileId file_id) = 0; virtual td_api::object_ptr get_file_download_object(FileId file_id, FileSourceId file_source_id, diff --git a/td/telegram/DownloadManagerCallback.cpp b/td/telegram/DownloadManagerCallback.cpp index b41f119c4..a1eeacf50 100644 --- a/td/telegram/DownloadManagerCallback.cpp +++ b/td/telegram/DownloadManagerCallback.cpp @@ -64,6 +64,12 @@ FileId DownloadManagerCallback::dup_file_id(FileId file_id) { return td_->file_manager_->dup_file_id(file_id); } +void DownloadManagerCallback::get_file_search_text(FileId file_id, FileSourceId file_source_id, + Promise &&promise) { + send_closure(td_->file_reference_manager_actor_, &FileReferenceManager::get_file_search_text, file_source_id, + get_file_view(file_id).get_unique_file_id(), std::move(promise)); +} + FileView DownloadManagerCallback::get_file_view(FileId file_id) { return td_->file_manager_->get_file_view(file_id); } diff --git a/td/telegram/DownloadManagerCallback.h b/td/telegram/DownloadManagerCallback.h index 145ae7f92..769a17543 100644 --- a/td/telegram/DownloadManagerCallback.h +++ b/td/telegram/DownloadManagerCallback.h @@ -45,7 +45,7 @@ class DownloadManagerCallback final : public DownloadManager::Callback { FileId dup_file_id(FileId file_id) final; - FileView get_file_view(FileId file_id) final; + void get_file_search_text(FileId file_id, FileSourceId file_source_id, Promise &&promise) final; FileView get_sync_file_view(FileId file_id) final; @@ -57,6 +57,8 @@ class DownloadManagerCallback final : public DownloadManager::Callback { Td *td_; ActorShared<> parent_; + FileView get_file_view(FileId file_id); + static std::shared_ptr make_download_file_callback( Td *td, ActorShared download_manager); };