From 60582a24abc37f44719c7a080aae197803a34eb6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 18 Apr 2018 21:23:37 +0400 Subject: [PATCH] Fix passport selfie requirements. --- .../passport/passport_form_controller.cpp | 2 +- .../passport/passport_panel_edit_scans.cpp | 57 +++++++++++-------- .../passport/passport_panel_edit_scans.h | 4 ++ 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/Telegram/SourceFiles/passport/passport_form_controller.cpp b/Telegram/SourceFiles/passport/passport_form_controller.cpp index fefa5a7b21..8845af4140 100644 --- a/Telegram/SourceFiles/passport/passport_form_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_form_controller.cpp @@ -1004,7 +1004,7 @@ void FormController::startValueEdit(not_null value) { for (auto &scan : nonconst->scans) { loadFile(scan); } - if (nonconst->selfie) { + if (nonconst->selfie && _form.identitySelfieRequired) { loadFile(*nonconst->selfie); } nonconst->scansInEdit = ranges::view::all( diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp index a4e131866a..9648455766 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_scans.cpp @@ -370,29 +370,8 @@ void EditScans::setupContent(const QString &header) { } void EditScans::updateScan(ScanInfo &&info) { - const auto updateRow = [&]( - not_null button, - const ScanInfo &info) { - button->setStatus(info.status); - button->setImage(info.thumb); - button->setDeleted(info.deleted); - button->setError(!info.error.isEmpty()); - }; if (info.selfie) { - Assert(info.key.id != 0); - Assert(_selfie != nullptr); - if (_selfie->key.id) { - updateRow(_selfieRow->entity(), info); - if (!info.deleted) { - hideSelfieError(); - } - } else { - createSelfieRow(info); - _selfieWrap->resizeToWidth(width()); - _selfieRow->show(anim::type::normal); - _selfieHeader->show(anim::type::normal); - } - *_selfie = std::move(info); + updateSelfie(std::move(info)); return; } const auto i = ranges::find(_files, info.key, [](const ScanInfo &file) { @@ -401,9 +380,7 @@ void EditScans::updateScan(ScanInfo &&info) { if (i != _files.end()) { *i = std::move(info); const auto scan = _rows[i - _files.begin()]->entity(); - scan->setStatus(i->status); - scan->setImage(i->thumb); - scan->setDeleted(i->deleted); + updateFileRow(scan, *i); if (!i->deleted) { hideError(); } @@ -421,6 +398,36 @@ void EditScans::updateScan(ScanInfo &&info) { } } +void EditScans::updateSelfie(ScanInfo &&info) { + Expects(info.key.id != 0); + + if (!_selfie) { + return; + } + if (_selfie->key.id) { + updateFileRow(_selfieRow->entity(), info); + if (!info.deleted) { + hideSelfieError(); + } + } else { + createSelfieRow(info); + _selfieWrap->resizeToWidth(width()); + _selfieRow->show(anim::type::normal); + _selfieHeader->show(anim::type::normal); + } + *_selfie = std::move(info); +} + +void EditScans::updateFileRow( + not_null button, + const ScanInfo &info) { + button->setStatus(info.status); + button->setImage(info.thumb); + button->setDeleted(info.deleted); + button->setError(!info.error.isEmpty()); +}; + + void EditScans::createSelfieRow(const ScanInfo &info) { _selfieRow = createScan( _selfieWrap, diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_scans.h b/Telegram/SourceFiles/passport/passport_panel_edit_scans.h index 89cbdf3b80..4addb0db5c 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_scans.h +++ b/Telegram/SourceFiles/passport/passport_panel_edit_scans.h @@ -51,6 +51,10 @@ private: void chooseScan(); void chooseSelfie(); void updateScan(ScanInfo &&info); + void updateSelfie(ScanInfo &&info); + void updateFileRow( + not_null button, + const ScanInfo &info); void pushScan(const ScanInfo &info); void createSelfieRow(const ScanInfo &info); base::unique_qptr> createScan(