mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Moved load status of files in passport to separated class.
This commit is contained in:
parent
401529e7d1
commit
559d488b0b
3 changed files with 57 additions and 22 deletions
|
@ -1438,7 +1438,7 @@ void FormController::prepareFile(
|
|||
file.fields.secret = GenerateSecretBytes();
|
||||
file.fields.date = base::unixtime::now();
|
||||
file.fields.image = ReadImage(bytes::make_span(content));
|
||||
file.fields.downloadOffset = file.fields.size;
|
||||
file.fields.downloadStatus.set(LoadStatus::Status::Done);
|
||||
|
||||
_scanUpdated.fire(&file);
|
||||
}
|
||||
|
@ -1558,6 +1558,7 @@ void FormController::uploadEncryptedFile(
|
|||
file.uploadData->fullId = FullMsgId(
|
||||
0,
|
||||
session().data().nextLocalMessageId());
|
||||
file.uploadData->status.set(LoadStatus::Status::InProgress, 0);
|
||||
session().uploader().upload(
|
||||
file.uploadData->fullId,
|
||||
std::move(prepared));
|
||||
|
@ -1575,6 +1576,7 @@ void FormController::scanUploadDone(const Storage::UploadSecureDone &data) {
|
|||
_secret,
|
||||
file->fields.hash);
|
||||
file->uploadData->fullId = FullMsgId();
|
||||
file->uploadData->status.set(LoadStatus::Status::Done);
|
||||
|
||||
_scanUpdated.fire(file);
|
||||
}
|
||||
|
@ -1585,7 +1587,9 @@ void FormController::scanUploadProgress(
|
|||
if (const auto file = findEditFile(data.fullId)) {
|
||||
Assert(file->uploadData != nullptr);
|
||||
|
||||
file->uploadData->offset = data.offset;
|
||||
file->uploadData->status.set(
|
||||
LoadStatus::Status::InProgress,
|
||||
data.offset);
|
||||
|
||||
_scanUpdated.fire(file);
|
||||
}
|
||||
|
@ -1595,7 +1599,7 @@ void FormController::scanUploadFail(const FullMsgId &fullId) {
|
|||
if (const auto file = findEditFile(fullId)) {
|
||||
Assert(file->uploadData != nullptr);
|
||||
|
||||
file->uploadData->offset = -1;
|
||||
file->uploadData->status.set(LoadStatus::Status::Failed);
|
||||
|
||||
_scanUpdated.fire(file);
|
||||
}
|
||||
|
@ -1737,7 +1741,7 @@ void FormController::startValueEdit(not_null<const Value*> value) {
|
|||
|
||||
void FormController::loadFile(File &file) {
|
||||
if (!file.image.isNull()) {
|
||||
file.downloadOffset = file.size;
|
||||
file.downloadStatus.set(LoadStatus::Status::Done);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1746,7 +1750,7 @@ void FormController::loadFile(File &file) {
|
|||
if (i != _fileLoaders.end()) {
|
||||
return;
|
||||
}
|
||||
file.downloadOffset = 0;
|
||||
file.downloadStatus.set(LoadStatus::Status::InProgress, 0);
|
||||
const auto [j, ok] = _fileLoaders.emplace(
|
||||
key,
|
||||
std::make_unique<mtpFileLoader>(
|
||||
|
@ -1788,11 +1792,11 @@ void FormController::fileLoadDone(FileKey key, const QByteArray &bytes) {
|
|||
fileLoadFail(key);
|
||||
return;
|
||||
}
|
||||
file->downloadOffset = file->size;
|
||||
file->downloadStatus.set(LoadStatus::Status::Done);
|
||||
file->image = ReadImage(gsl::make_span(decrypted));
|
||||
if (const auto fileInEdit = findEditFile(key)) {
|
||||
fileInEdit->fields.image = file->image;
|
||||
fileInEdit->fields.downloadOffset = file->downloadOffset;
|
||||
fileInEdit->fields.downloadStatus = file->downloadStatus;
|
||||
_scanUpdated.fire(fileInEdit);
|
||||
}
|
||||
}
|
||||
|
@ -1800,9 +1804,9 @@ void FormController::fileLoadDone(FileKey key, const QByteArray &bytes) {
|
|||
|
||||
void FormController::fileLoadProgress(FileKey key, int offset) {
|
||||
if (const auto [value, file] = findFile(key); file != nullptr) {
|
||||
file->downloadOffset = offset;
|
||||
file->downloadStatus.set(LoadStatus::Status::InProgress, offset);
|
||||
if (const auto fileInEdit = findEditFile(key)) {
|
||||
fileInEdit->fields.downloadOffset = file->downloadOffset;
|
||||
fileInEdit->fields.downloadStatus = file->downloadStatus;
|
||||
_scanUpdated.fire(fileInEdit);
|
||||
}
|
||||
}
|
||||
|
@ -1810,9 +1814,9 @@ void FormController::fileLoadProgress(FileKey key, int offset) {
|
|||
|
||||
void FormController::fileLoadFail(FileKey key) {
|
||||
if (const auto [value, file] = findFile(key); file != nullptr) {
|
||||
file->downloadOffset = -1;
|
||||
file->downloadStatus.set(LoadStatus::Status::Failed);
|
||||
if (const auto fileInEdit = findEditFile(key)) {
|
||||
fileInEdit->fields.downloadOffset = file->downloadOffset;
|
||||
fileInEdit->fields.downloadStatus = file->downloadStatus;
|
||||
_scanUpdated.fire(fileInEdit);
|
||||
}
|
||||
}
|
||||
|
@ -2361,7 +2365,7 @@ void FormController::fillDownloadedFile(
|
|||
return;
|
||||
}
|
||||
destination.image = i->fields.image;
|
||||
destination.downloadOffset = i->fields.downloadOffset;
|
||||
destination.downloadStatus = i->fields.downloadStatus;
|
||||
if (!i->uploadData) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -64,6 +64,35 @@ struct FormRequest {
|
|||
|
||||
};
|
||||
|
||||
class LoadStatus final {
|
||||
public:
|
||||
enum class Status {
|
||||
Done,
|
||||
InProgress,
|
||||
Failed,
|
||||
};
|
||||
|
||||
LoadStatus() = default;
|
||||
|
||||
void set(Status status, int offset = 0) {
|
||||
if (!offset) {
|
||||
offset = _offset;
|
||||
}
|
||||
_offset = (status == Status::InProgress) ? offset : 0;
|
||||
_status = status;
|
||||
}
|
||||
|
||||
int offset() const {
|
||||
return _offset;
|
||||
}
|
||||
Status status() const {
|
||||
return _status;
|
||||
}
|
||||
private:
|
||||
int _offset = 0;
|
||||
Status _status = Status::Done;
|
||||
};
|
||||
|
||||
struct UploadScanData {
|
||||
FullMsgId fullId;
|
||||
uint64 fileId = 0;
|
||||
|
@ -72,7 +101,7 @@ struct UploadScanData {
|
|||
bytes::vector hash;
|
||||
bytes::vector bytes;
|
||||
|
||||
int offset = 0;
|
||||
LoadStatus status;
|
||||
};
|
||||
|
||||
class UploadScanDataPointer {
|
||||
|
@ -115,7 +144,7 @@ struct File {
|
|||
bytes::vector secret;
|
||||
bytes::vector encryptedSecret;
|
||||
|
||||
int downloadOffset = 0;
|
||||
LoadStatus downloadStatus;
|
||||
QImage image;
|
||||
QString error;
|
||||
};
|
||||
|
|
|
@ -40,13 +40,14 @@ const auto kLanguageNamePrefix = "cloud_lng_passport_in_";
|
|||
ScanInfo CollectScanInfo(const EditFile &file) {
|
||||
const auto status = [&] {
|
||||
if (file.fields.accessHash) {
|
||||
if (file.fields.downloadOffset < 0) {
|
||||
switch (file.fields.downloadStatus.status()) {
|
||||
case LoadStatus::Status::Failed:
|
||||
return tr::lng_attach_failed(tr::now);
|
||||
} else if (file.fields.downloadOffset < file.fields.size) {
|
||||
case LoadStatus::Status::InProgress:
|
||||
return Ui::FormatDownloadText(
|
||||
file.fields.downloadOffset,
|
||||
file.fields.downloadStatus.offset(),
|
||||
file.fields.size);
|
||||
} else {
|
||||
case LoadStatus::Status::Done:
|
||||
return tr::lng_passport_scan_uploaded(
|
||||
tr::now,
|
||||
lt_date,
|
||||
|
@ -54,13 +55,14 @@ ScanInfo CollectScanInfo(const EditFile &file) {
|
|||
base::unixtime::parse(file.fields.date)));
|
||||
}
|
||||
} else if (file.uploadData) {
|
||||
if (file.uploadData->offset < 0) {
|
||||
switch (file.uploadData->status.status()) {
|
||||
case LoadStatus::Status::Failed:
|
||||
return tr::lng_attach_failed(tr::now);
|
||||
} else if (file.uploadData->fullId) {
|
||||
case LoadStatus::Status::InProgress:
|
||||
return Ui::FormatDownloadText(
|
||||
file.uploadData->offset,
|
||||
file.uploadData->status.offset(),
|
||||
file.uploadData->bytes.size());
|
||||
} else {
|
||||
case LoadStatus::Status::Done:
|
||||
return tr::lng_passport_scan_uploaded(
|
||||
tr::now,
|
||||
lt_date,
|
||||
|
|
Loading…
Add table
Reference in a new issue