More passport data fixes.

GitOrigin-RevId: b9d0c3244b5ce3a170679645e7ccb54fc0ad7ce2
This commit is contained in:
levlam 2018-04-24 20:10:12 +03:00
parent 1a0c874a67
commit 06a89db640
2 changed files with 32 additions and 5 deletions

View File

@ -104,6 +104,7 @@ class SetSecureValue : public NetQueryCallback {
void on_secret(Result<secure_storage::Secret> r_secret, bool x);
void start_up() override;
void hangup() override;
void tear_down() override;
void loop() override;
@ -290,7 +291,8 @@ SetSecureValue::UploadCallback::UploadCallback(ActorId<SetSecureValue> actor_id)
}
void SetSecureValue::UploadCallback::on_upload_ok(FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file) {
send_closure(actor_id_, &SetSecureValue::on_upload_ok, file_id, nullptr);
CHECK(input_file == nullptr);
send_closure_later(actor_id_, &SetSecureValue::on_upload_ok, file_id, nullptr);
}
void SetSecureValue::UploadCallback::on_upload_encrypted_ok(
FileId file_id, tl_object_ptr<telegram_api::InputEncryptedFile> input_file) {
@ -298,10 +300,10 @@ void SetSecureValue::UploadCallback::on_upload_encrypted_ok(
}
void SetSecureValue::UploadCallback::on_upload_secure_ok(FileId file_id,
tl_object_ptr<telegram_api::InputSecureFile> input_file) {
send_closure(actor_id_, &SetSecureValue::on_upload_ok, file_id, std::move(input_file));
send_closure_later(actor_id_, &SetSecureValue::on_upload_ok, file_id, std::move(input_file));
}
void SetSecureValue::UploadCallback::on_upload_error(FileId file_id, Status error) {
send_closure(actor_id_, &SetSecureValue::on_upload_error, file_id, std::move(error));
send_closure_later(actor_id_, &SetSecureValue::on_upload_error, file_id, std::move(error));
}
void SetSecureValue::on_upload_ok(FileId file_id, tl_object_ptr<telegram_api::InputSecureFile> input_file) {
@ -324,6 +326,7 @@ void SetSecureValue::on_upload_ok(FileId file_id, tl_object_ptr<telegram_api::In
files_left_to_upload_--;
return loop();
}
void SetSecureValue::on_upload_error(FileId file_id, Status error) {
return on_error(std::move(error));
}
@ -359,6 +362,7 @@ void SetSecureValue::start_up() {
FileId selfie_file_id;
if (secure_value_.selfie.file_id.is_valid()) {
selfie_file_id = file_manager->get_file_view(secure_value_.selfie.file_id).file_id();
selfie_ = SecureInputFile();
}
for (auto it = secure_value_.files.begin(); it != secure_value_.files.end();) {
auto file_id = file_manager->get_file_view(it->file_id).file_id();
@ -375,13 +379,18 @@ void SetSecureValue::start_up() {
++it;
}
}
if (selfie_ && secure_value_.files.empty()) {
secure_value_.files.push_back(std::move(secure_value_.selfie));
selfie_ = optional<SecureInputFile>();
secure_value_.selfie = DatedFile();
}
to_upload_.resize(secure_value_.files.size());
upload_callback_ = std::make_shared<UploadCallback>(actor_id(this));
for (size_t i = 0; i < to_upload_.size(); i++) {
start_upload(file_manager, secure_value_.files[i].file_id, to_upload_[i]);
}
if (secure_value_.selfie.file_id.is_valid()) {
if (selfie_) {
start_upload(file_manager, secure_value_.selfie.file_id, selfie_.value());
}
}
@ -412,11 +421,18 @@ void SetSecureValue::loop() {
}
}
void SetSecureValue::hangup() {
on_error(Status::Error(406, "Request aborted"));
}
void SetSecureValue::tear_down() {
auto *file_manager = G()->td().get_actor_unsafe()->file_manager_.get();
for (auto &file_info : to_upload_) {
file_manager->upload(file_info.file_id, nullptr, 0, 0);
}
if (selfie_) {
file_manager->upload(selfie_.value().file_id, nullptr, 0, 0);
}
}
void SetSecureValue::on_result(NetQueryPtr query) {

View File

@ -1406,8 +1406,10 @@ void FileManager::delete_file(FileId file_id, Promise<Unit> promise, const char
}
void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> callback, int32 new_priority) {
LOG(INFO) << "Download file " << file_id << " with priority " << new_priority;
auto node = get_sync_file_node(file_id);
if (!node) {
LOG(INFO) << "File " << file_id << " not found";
if (callback) {
callback->on_download_error(file_id, Status::Error("File not found"));
}
@ -1419,6 +1421,7 @@ void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> cal
if (status.is_error()) {
LOG(WARNING) << "Need to redownload file " << file_id << ": " << status.error();
} else {
LOG(INFO) << "File " << file_id << " is already downloaded";
if (callback) {
callback->on_download_ok(file_id);
}
@ -1433,6 +1436,7 @@ void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> cal
FileView file_view(node);
if (!file_view.can_download_from_server() && !file_view.can_generate()) {
LOG(INFO) << "File " << file_id << " can't be downloaded";
if (callback) {
callback->on_download_error(file_id, Status::Error("Can't download or generate file"));
}
@ -1441,11 +1445,14 @@ void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> cal
if (new_priority == -1) {
if (node->is_download_started_) {
LOG(INFO) << "File " << file_id << " is being downloaded";
return;
}
new_priority = 0;
}
LOG(INFO) << "Change download priority of file " << file_id << " to " << new_priority;
auto *file_info = get_file_id_info(file_id);
CHECK(new_priority == 0 || callback);
file_info->download_priority_ = narrow_cast<int8>(new_priority);
@ -1509,8 +1516,9 @@ void FileManager::resume_upload(FileId file_id, std::vector<int> bad_parts, std:
auto node = get_sync_file_node(file_id);
if (!node) {
LOG(INFO) << "File " << file_id << " not found";
if (callback) {
callback->on_upload_error(file_id, Status::Error("Wrong file id to upload"));
callback->on_upload_error(file_id, Status::Error("File not found"));
}
return;
}
@ -1520,6 +1528,7 @@ void FileManager::resume_upload(FileId file_id, std::vector<int> bad_parts, std:
FileView file_view(node);
if (file_view.has_remote_location() && file_view.get_type() != FileType::Thumbnail &&
file_view.get_type() != FileType::EncryptedThumbnail) {
LOG(INFO) << "File " << file_id << " is already uploaded";
if (callback) {
callback->on_upload_ok(file_id, nullptr);
}
@ -1534,12 +1543,14 @@ void FileManager::resume_upload(FileId file_id, std::vector<int> bad_parts, std:
}
if (!file_view.has_local_location() && !file_view.has_generate_location()) {
LOG(INFO) << "File " << file_id << " can't be uploaded";
if (callback) {
callback->on_upload_error(file_id, Status::Error("Need full local (or generate) location for upload"));
}
return;
}
LOG(INFO) << "Change upload priority of file " << file_id << " to " << new_priority;
auto *file_info = get_file_id_info(file_id);
CHECK(new_priority == 0 || callback);
file_info->upload_order_ = upload_order;