From da436915c14f80856ae7b8e4d5cb43daa6ff45ac Mon Sep 17 00:00:00 2001 From: Arseny Smirnov Date: Fri, 25 Feb 2022 15:57:08 +0100 Subject: [PATCH] implement DownloadManagerCallback --- td/telegram/DownloadManager.cpp | 4 +++- td/telegram/DownloadManager.h | 2 ++ td/telegram/Td.cpp | 27 ++++++++++++++------------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/td/telegram/DownloadManager.cpp b/td/telegram/DownloadManager.cpp index 52a009477..3d3a9fca9 100644 --- a/td/telegram/DownloadManager.cpp +++ b/td/telegram/DownloadManager.cpp @@ -205,5 +205,7 @@ unique_ptr DownloadManager::create() { tl_object_ptr DownloadManager::FoundFileDownloads::to_td_api() const { return make_tl_object(); } - +tl_object_ptr DownloadManager::Counters::to_td_api() const { + return make_tl_object(total_size, total_count, downloaded_size); +} } // namespace td diff --git a/td/telegram/DownloadManager.h b/td/telegram/DownloadManager.h index db0518e43..df86c96ea 100644 --- a/td/telegram/DownloadManager.h +++ b/td/telegram/DownloadManager.h @@ -27,6 +27,8 @@ class DownloadManager : public Actor { int64 total_size{}; int32 total_count{}; int64 downloaded_size{}; + + tl_object_ptr to_td_api() const; }; struct FileDownload { diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index fe9398590..85614f9a2 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -3975,39 +3975,40 @@ void Td::init_managers() { // TODO: move this callback somewhere else class DownloadManagerCallback final : public DownloadManager::Callback { public: - explicit DownloadManagerCallback(ActorShared<> parent) : parent_(std::move(parent)) { - // TODO + DownloadManagerCallback(ActorShared<> parent, std::shared_ptr download_file_callback) + : parent_(std::move(parent)), download_file_callback_(std::move(download_file_callback)) { } void update_counters(DownloadManager::Counters counters) final { - // TODO + send_closure(G()->td(), &Td::send_update, counters.to_td_api()); } void start_file(FileId file_id, int8 priority) final { - // TODO + send_closure(G()->file_manager(), &FileManager::download, file_id, download_file_callback_, priority, -1, -1); } void pause_file(FileId file_id) final { - // TODO + send_closure(G()->file_manager(), &FileManager::download, file_id, nullptr, 0, -1, -1); } void delete_file(FileId file_id) final { - // TODO + send_closure( + G()->file_manager(), &FileManager::delete_file, file_id, [](Result) {}, "download manager callback"); } FileId dup_file_id(FileId file_id) final { - // TODO - return FileId(); + return G()->file_manager().get_actor_unsafe()->dup_file_id(file_id); } string get_unique_file_id(FileId file_id) final { - // TODO - return string(); + return G()->file_manager().get_actor_unsafe()->get_file_view(file_id).get_unique_file_id(); } string get_file_source_serialized(FileSourceId file_source_id) final { - // TODO - return string(); + TlStorerToString storer; + G()->file_reference_manager().get_actor_unsafe()->store_file_source(file_source_id, storer); + return storer.move_as_string(); } private: ActorShared<> parent_; + std::shared_ptr download_file_callback_; }; send_closure_later(download_manager_actor_, &DownloadManager::set_callback, - make_unique(create_reference())); + td::make_unique(create_reference(), download_file_callback_)); game_manager_ = make_unique(this, create_reference()); game_manager_actor_ = register_actor("GameManager", game_manager_.get());