Make DownloadManager::add_file asynchronous.
This commit is contained in:
parent
ec19eaad65
commit
698b34709f
@ -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<td_api::object_ptr<td_api::file>> 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 {
|
||||
|
@ -76,6 +76,7 @@ class DownloadManager : public Actor {
|
||||
virtual void get_file_search_text(FileId file_id, FileSourceId file_source_id, Promise<string> &&promise) = 0;
|
||||
|
||||
virtual FileView get_sync_file_view(FileId file_id) = 0;
|
||||
virtual td_api::object_ptr<td_api::file> get_file_object(FileId file_id) = 0;
|
||||
virtual td_api::object_ptr<td_api::fileDownload> 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<td_api::object_ptr<td_api::file>> promise) = 0;
|
||||
virtual void toggle_is_paused(FileId file_id, bool is_paused, Promise<Unit> promise) = 0;
|
||||
virtual void toggle_all_is_paused(bool is_paused, Promise<Unit> 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;
|
||||
|
@ -79,6 +79,10 @@ FileView DownloadManagerCallback::get_sync_file_view(FileId file_id) {
|
||||
return get_file_view(file_id);
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::file> DownloadManagerCallback::get_file_object(FileId file_id) {
|
||||
return td_->file_manager_->get_file_object(file_id);
|
||||
}
|
||||
|
||||
td_api::object_ptr<td_api::fileDownload> 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_api::fileDownload>(td_->file_manager_->get_file_view(file_id).get_main_file_id().get(),
|
||||
|
@ -49,9 +49,11 @@ class DownloadManagerCallback final : public DownloadManager::Callback {
|
||||
|
||||
FileView get_sync_file_view(FileId file_id) final;
|
||||
|
||||
td_api::object_ptr<td_api::file> get_file_object(FileId file_id) final;
|
||||
|
||||
td_api::object_ptr<td_api::fileDownload> 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_;
|
||||
|
@ -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<int8>(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<int8>(priority), std::move(promise));
|
||||
}
|
||||
|
||||
void MessagesManager::get_message_file_search_text(FullMessageId full_message_id, string unique_file_id,
|
||||
|
Loading…
Reference in New Issue
Block a user