Add only_if_pending to cancelDownloadFile.

GitOrigin-RevId: 7280c353b4903e565c2e0a2557d50317f6f7c886
This commit is contained in:
levlam 2018-01-16 17:41:47 +03:00
parent f856a383ad
commit d6fb230324
5 changed files with 11 additions and 4 deletions

View File

@ -2314,8 +2314,8 @@ setPinnedChats chat_ids:vector<int53> = 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 //@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; 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 //@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 = Ok; 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 //@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 //@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

Binary file not shown.

View File

@ -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) { void Td::on_request(uint64 id, const td_api::cancelDownloadFile &request) {
CHECK_AUTH(); 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<td_api::ok>()); send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>());
} }

View File

@ -1796,7 +1796,7 @@ class CliClient final : public Actor {
send_request(make_tl_object<td_api::downloadFile>(i, to_integer<int32>(priority))); send_request(make_tl_object<td_api::downloadFile>(i, to_integer<int32>(priority)));
} }
} else if (op == "cdf") { } else if (op == "cdf") {
send_request(make_tl_object<td_api::cancelDownloadFile>(as_file_id(args))); send_request(make_tl_object<td_api::cancelDownloadFile>(as_file_id(args), true));
} else if (op == "uf") { } else if (op == "uf") {
string file_path; string file_path;
string priority; string priority;

View File

@ -1339,6 +1339,13 @@ void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> cal
return; return;
} }
if (new_priority == -1) {
if (node->is_download_started_) {
return;
}
new_priority = 0;
}
auto *file_info = get_file_id_info(file_id); auto *file_info = get_file_id_info(file_id);
CHECK(new_priority == 0 || callback); CHECK(new_priority == 0 || callback);
file_info->download_priority_ = new_priority; file_info->download_priority_ = new_priority;