diff --git a/td/telegram/DownloadManager.cpp b/td/telegram/DownloadManager.cpp index ca60fa40e..97b629622 100644 --- a/td/telegram/DownloadManager.cpp +++ b/td/telegram/DownloadManager.cpp @@ -175,8 +175,9 @@ class DownloadManagerImpl final : public DownloadManager { promise.set_value(Unit()); } - Status add_file(FileId file_id, FileSourceId file_source_id, string search_text, int8 priority) final { - TRY_STATUS(check_is_active()); + void add_file(FileId file_id, FileSourceId file_source_id, string search_text, int8 priority, + Promise> promise) final { + TRY_STATUS_PROMISE(promise, check_is_active()); remove_file_impl(file_id, {}, false); @@ -193,7 +194,7 @@ class DownloadManagerImpl final : public DownloadManager { add_file_info(std::move(file_info), search_text); - return Status::OK(); + promise.set_value(callback_->get_file_object(file_id)); } void change_search_text(FileId file_id, FileSourceId file_source_id, string search_text) final { diff --git a/td/telegram/DownloadManager.h b/td/telegram/DownloadManager.h index b34d20ae2..de2133944 100644 --- a/td/telegram/DownloadManager.h +++ b/td/telegram/DownloadManager.h @@ -76,6 +76,7 @@ class DownloadManager : public Actor { 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_object(FileId file_id) = 0; virtual td_api::object_ptr get_file_download_object(FileId file_id, FileSourceId file_source_id, int32 add_date, int32 complete_date, @@ -87,10 +88,8 @@ class DownloadManager : public Actor { // // public interface for user // - virtual void after_get_difference() = 0; - virtual Status add_file(FileId file_id, FileSourceId file_source_id, string search_text, int8 priority) = 0; - virtual void change_search_text(FileId file_id, FileSourceId file_source_id, string search_text) = 0; - virtual void remove_file_if_finished(FileId file_id) = 0; + virtual void add_file(FileId file_id, FileSourceId file_source_id, string search_text, int8 priority, + Promise> promise) = 0; virtual void toggle_is_paused(FileId file_id, bool is_paused, Promise promise) = 0; virtual void toggle_all_is_paused(bool is_paused, Promise promise) = 0; virtual void search(string query, bool only_active, bool only_completed, string offset, int32 limit, @@ -103,6 +102,9 @@ class DownloadManager : public Actor { // // private interface to handle all kinds of updates // + virtual void after_get_difference() = 0; + virtual void change_search_text(FileId file_id, FileSourceId file_source_id, string search_text) = 0; + virtual void remove_file_if_finished(FileId file_id) = 0; virtual void update_file_download_state(FileId internal_file_id, int64 downloaded_size, int64 size, int64 expected_size, bool is_paused) = 0; virtual void update_file_deleted(FileId internal_file_id) = 0; diff --git a/td/telegram/DownloadManagerCallback.cpp b/td/telegram/DownloadManagerCallback.cpp index a1eeacf50..8b3622299 100644 --- a/td/telegram/DownloadManagerCallback.cpp +++ b/td/telegram/DownloadManagerCallback.cpp @@ -79,6 +79,10 @@ FileView DownloadManagerCallback::get_sync_file_view(FileId file_id) { return get_file_view(file_id); } +td_api::object_ptr DownloadManagerCallback::get_file_object(FileId file_id) { + return td_->file_manager_->get_file_object(file_id); +} + td_api::object_ptr DownloadManagerCallback::get_file_download_object( FileId file_id, FileSourceId file_source_id, int32 add_date, int32 complete_date, bool is_paused) { return td_api::make_object(td_->file_manager_->get_file_view(file_id).get_main_file_id().get(), diff --git a/td/telegram/DownloadManagerCallback.h b/td/telegram/DownloadManagerCallback.h index 769a17543..19da9c842 100644 --- a/td/telegram/DownloadManagerCallback.h +++ b/td/telegram/DownloadManagerCallback.h @@ -49,9 +49,11 @@ class DownloadManagerCallback final : public DownloadManager::Callback { FileView get_sync_file_view(FileId file_id) final; + td_api::object_ptr get_file_object(FileId file_id) final; + td_api::object_ptr get_file_download_object(FileId file_id, FileSourceId file_source_id, int32 add_date, int32 complete_date, - bool is_paused); + bool is_paused) final; private: Td *td_; diff --git a/td/telegram/MessagesManager.cpp b/td/telegram/MessagesManager.cpp index 7f7c66d03..5f668f331 100644 --- a/td/telegram/MessagesManager.cpp +++ b/td/telegram/MessagesManager.cpp @@ -40148,9 +40148,8 @@ void MessagesManager::add_message_file_to_downloads(FullMessageId full_message_i auto search_text = get_message_search_text(m); auto file_source_id = get_message_file_source_id(full_message_id, true); CHECK(file_source_id.is_valid()); - TRY_STATUS_PROMISE(promise, td_->download_manager_->add_file(file_id, file_source_id, std::move(search_text), - static_cast(priority))); - promise.set_value(td_->file_manager_->get_file_object(file_id)); + send_closure(td_->download_manager_actor_, &DownloadManager::add_file, file_id, file_source_id, + std::move(search_text), static_cast(priority), std::move(promise)); } void MessagesManager::get_message_file_search_text(FullMessageId full_message_id, string unique_file_id,