diff --git a/td/generate/scheme/td_api.tl b/td/generate/scheme/td_api.tl index d370f161..f41f8b68 100644 --- a/td/generate/scheme/td_api.tl +++ b/td/generate/scheme/td_api.tl @@ -2314,8 +2314,8 @@ setPinnedChats chat_ids:vector = Ok; //@priority Priority of the download (1-32). The higher the priority, the earlier the file will be downloaded. If the priorities of two files are equal, then the last one for which downloadFile was called will be downloaded first downloadFile file_id:int32 priority:int32 = File; -//@description Stops the downloading of a file. If a file has already been downloaded, does nothing @file_id Identifier of a file to stop downloading -cancelDownloadFile file_id:int32 = Ok; +//@description Stops the downloading of a file. If a file has already been downloaded, does nothing @file_id Identifier of a file to stop downloading @only_if_pending Pass true to stop downloading only if it hasn't been started, i.e. request hasn't been sent to server +cancelDownloadFile file_id:int32 only_if_pending:Bool = Ok; //@description Asynchronously uploads a file to the cloud without sending it in a message. updateFile will be used to notify about upload progress and successful completion of the upload. The file will not have a persistent remote identifier until it will be sent in a message @file File to upload @file_type File type //@priority Priority of the upload (1-32). The higher the priority, the earlier the file will be uploaded. If the priorities of two files are equal, then the first one for which uploadFile was called will be uploaded first diff --git a/td/generate/scheme/td_api.tlo b/td/generate/scheme/td_api.tlo index ef1811c1..52054315 100644 Binary files a/td/generate/scheme/td_api.tlo and b/td/generate/scheme/td_api.tlo differ diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 5a6db518..304f9996 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -5568,7 +5568,7 @@ void Td::on_request(uint64 id, const td_api::downloadFile &request) { void Td::on_request(uint64 id, const td_api::cancelDownloadFile &request) { CHECK_AUTH(); - file_manager_->download(FileId(request.file_id_), nullptr, 0); + file_manager_->download(FileId(request.file_id_), nullptr, request.only_if_pending_ ? -1 : 0); send_closure(actor_id(this), &Td::send_result, id, make_tl_object()); } diff --git a/td/telegram/cli.cpp b/td/telegram/cli.cpp index 17282005..d8375047 100644 --- a/td/telegram/cli.cpp +++ b/td/telegram/cli.cpp @@ -1796,7 +1796,7 @@ class CliClient final : public Actor { send_request(make_tl_object(i, to_integer(priority))); } } else if (op == "cdf") { - send_request(make_tl_object(as_file_id(args))); + send_request(make_tl_object(as_file_id(args), true)); } else if (op == "uf") { string file_path; string priority; diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 11bcdb7b..14fd368f 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -1339,6 +1339,13 @@ void FileManager::download(FileId file_id, std::shared_ptr cal return; } + if (new_priority == -1) { + if (node->is_download_started_) { + return; + } + new_priority = 0; + } + auto *file_info = get_file_id_info(file_id); CHECK(new_priority == 0 || callback); file_info->download_priority_ = new_priority;