2018-04-03 18:24:31 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "passport/passport_form_view_controller.h"
|
|
|
|
|
|
|
|
#include "passport/passport_form_controller.h"
|
2018-04-12 15:45:04 +00:00
|
|
|
#include "passport/passport_panel_edit_document.h"
|
|
|
|
#include "passport/passport_panel_edit_contact.h"
|
|
|
|
#include "passport/passport_panel_controller.h"
|
|
|
|
#include "lang/lang_keys.h"
|
2018-04-03 18:24:31 +00:00
|
|
|
|
|
|
|
namespace Passport {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
std::map<Value::Type, Scope::Type> ScopeTypesMap() {
|
|
|
|
return {
|
2018-08-12 19:48:43 +00:00
|
|
|
{ Value::Type::PersonalDetails, Scope::Type::PersonalDetails },
|
2018-04-03 18:24:31 +00:00
|
|
|
{ Value::Type::Passport, Scope::Type::Identity },
|
|
|
|
{ Value::Type::DriverLicense, Scope::Type::Identity },
|
|
|
|
{ Value::Type::IdentityCard, Scope::Type::Identity },
|
2018-05-11 22:55:56 +00:00
|
|
|
{ Value::Type::InternalPassport, Scope::Type::Identity },
|
2018-08-12 19:48:43 +00:00
|
|
|
{ Value::Type::Address, Scope::Type::AddressDetails },
|
2018-04-03 18:24:31 +00:00
|
|
|
{ Value::Type::UtilityBill, Scope::Type::Address },
|
|
|
|
{ Value::Type::BankStatement, Scope::Type::Address },
|
|
|
|
{ Value::Type::RentalAgreement, Scope::Type::Address },
|
2018-05-11 22:55:56 +00:00
|
|
|
{ Value::Type::PassportRegistration, Scope::Type::Address },
|
|
|
|
{ Value::Type::TemporaryRegistration, Scope::Type::Address },
|
2018-04-03 18:24:31 +00:00
|
|
|
{ Value::Type::Phone, Scope::Type::Phone },
|
|
|
|
{ Value::Type::Email, Scope::Type::Email },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
Scope::Type ScopeTypeForValueType(Value::Type type) {
|
|
|
|
static const auto map = ScopeTypesMap();
|
|
|
|
const auto i = map.find(type);
|
|
|
|
Assert(i != map.end());
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
|
2018-08-12 19:48:43 +00:00
|
|
|
std::map<Scope::Type, Value::Type> ScopeDetailsMap() {
|
2018-04-03 18:24:31 +00:00
|
|
|
return {
|
2018-08-12 19:48:43 +00:00
|
|
|
{ Scope::Type::PersonalDetails, Value::Type::PersonalDetails },
|
2018-04-03 18:24:31 +00:00
|
|
|
{ Scope::Type::Identity, Value::Type::PersonalDetails },
|
2018-08-12 19:48:43 +00:00
|
|
|
{ Scope::Type::AddressDetails, Value::Type::Address },
|
2018-04-03 18:24:31 +00:00
|
|
|
{ Scope::Type::Address, Value::Type::Address },
|
|
|
|
{ Scope::Type::Phone, Value::Type::Phone },
|
|
|
|
{ Scope::Type::Email, Value::Type::Email },
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-08-12 19:48:43 +00:00
|
|
|
Value::Type DetailsTypeForScopeType(Scope::Type type) {
|
|
|
|
static const auto map = ScopeDetailsMap();
|
2018-04-03 18:24:31 +00:00
|
|
|
const auto i = map.find(type);
|
|
|
|
Assert(i != map.end());
|
|
|
|
return i->second;
|
|
|
|
}
|
|
|
|
|
2018-08-12 19:48:43 +00:00
|
|
|
bool InlineDetails(
|
|
|
|
const Form::Request &request,
|
|
|
|
Scope::Type into,
|
|
|
|
Value::Type details) {
|
|
|
|
const auto count = ranges::count_if(
|
|
|
|
request,
|
|
|
|
[&](const std::vector<Value::Type> &types) {
|
|
|
|
Expects(!types.empty());
|
|
|
|
|
|
|
|
return ScopeTypeForValueType(types[0]) == into;
|
|
|
|
});
|
|
|
|
if (count != 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto has = ranges::find_if(
|
|
|
|
request,
|
|
|
|
[&](const std::vector<Value::Type> &types) {
|
|
|
|
Expects(!types.empty());
|
|
|
|
|
|
|
|
return (types[0] == details);
|
|
|
|
}
|
|
|
|
) != end(request);
|
|
|
|
return has;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool InlineDetails(const Form::Request &request, Value::Type details) {
|
|
|
|
if (details == Value::Type::PersonalDetails) {
|
|
|
|
return InlineDetails(request, Scope::Type::Identity, details);
|
|
|
|
} else if (details == Value::Type::Address) {
|
|
|
|
return InlineDetails(request, Scope::Type::Address, details);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-03 18:24:31 +00:00
|
|
|
} // namespace
|
|
|
|
|
2018-08-12 19:48:43 +00:00
|
|
|
Scope::Scope(Type type) : type(type) {
|
|
|
|
}
|
|
|
|
|
2018-08-14 11:37:03 +00:00
|
|
|
bool CanRequireSelfie(Value::Type type) {
|
|
|
|
const auto scope = ScopeTypeForValueType(type);
|
|
|
|
return (scope == Scope::Type::Address)
|
|
|
|
|| (scope == Scope::Type::Identity);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CanRequireScans(Value::Type type) {
|
|
|
|
const auto scope = ScopeTypeForValueType(type);
|
|
|
|
return (scope == Scope::Type::Address);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CanRequireTranslation(Value::Type type) {
|
|
|
|
const auto scope = ScopeTypeForValueType(type);
|
|
|
|
return (scope == Scope::Type::Address)
|
|
|
|
|| (scope == Scope::Type::Identity);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CanRequireNativeNames(Value::Type type) {
|
|
|
|
return (type == Value::Type::PersonalDetails);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CanHaveErrors(Value::Type type) {
|
|
|
|
return (type != Value::Type::Phone) && (type != Value::Type::Email);
|
|
|
|
}
|
|
|
|
|
2018-08-12 19:48:43 +00:00
|
|
|
bool ValidateForm(const Form &form) {
|
|
|
|
base::flat_set<Value::Type> values;
|
|
|
|
for (const auto &requested : form.request) {
|
|
|
|
if (requested.empty()) {
|
|
|
|
LOG(("API Error: Empty types list in authorization form row."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const auto scopeType = ScopeTypeForValueType(requested[0]);
|
|
|
|
const auto ownsDetails = (scopeType != Scope::Type::Identity
|
|
|
|
&& scopeType != Scope::Type::Address);
|
|
|
|
if (ownsDetails && requested.size() != 1) {
|
|
|
|
LOG(("API Error: Large types list in authorization form row."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (const auto type : requested) {
|
|
|
|
if (values.contains(type)) {
|
|
|
|
LOG(("API Error: Value twice in authorization form row."));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
values.emplace(type);
|
|
|
|
}
|
|
|
|
}
|
2018-08-14 11:37:03 +00:00
|
|
|
|
|
|
|
// Invalid errors should be skipped while parsing the form.
|
2018-08-12 19:48:43 +00:00
|
|
|
for (const auto &[type, value] : form.values) {
|
2018-08-14 11:37:03 +00:00
|
|
|
if (value.selfieRequired && !CanRequireSelfie(type)) {
|
|
|
|
LOG(("API Error: Bad value requiring selfie."));
|
|
|
|
return false;
|
|
|
|
} else if (value.translationRequired
|
|
|
|
&& !CanRequireTranslation(type)) {
|
|
|
|
LOG(("API Error: Bad value requiring translation."));
|
|
|
|
return false;
|
|
|
|
} else if (value.nativeNames && !CanRequireNativeNames(type)) {
|
|
|
|
LOG(("API Error: Bad value requiring native names."));
|
|
|
|
return false;
|
|
|
|
}
|
2018-08-14 15:27:47 +00:00
|
|
|
if (!value.requiresScan(FileType::Scan)) {
|
|
|
|
for (const auto &scan : value.files(FileType::Scan)) {
|
|
|
|
Assert(scan.error.isEmpty());
|
|
|
|
}
|
|
|
|
Assert(value.fileMissingError(FileType::Scan).isEmpty());
|
2018-08-14 11:37:03 +00:00
|
|
|
}
|
2018-08-14 15:27:47 +00:00
|
|
|
if (!value.requiresScan(FileType::Translation)) {
|
|
|
|
for (const auto &scan : value.files(FileType::Translation)) {
|
2018-08-14 11:37:03 +00:00
|
|
|
Assert(scan.error.isEmpty());
|
2018-08-12 19:48:43 +00:00
|
|
|
}
|
2018-08-14 15:27:47 +00:00
|
|
|
Assert(value.fileMissingError(FileType::Translation).isEmpty());
|
2018-08-12 19:48:43 +00:00
|
|
|
}
|
|
|
|
for (const auto &[type, specialScan] : value.specialScans) {
|
2018-08-14 11:37:03 +00:00
|
|
|
if (!value.requiresSpecialScan(type)) {
|
|
|
|
Assert(specialScan.error.isEmpty());
|
2018-08-12 19:48:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-08-14 11:37:03 +00:00
|
|
|
|
2018-08-12 19:48:43 +00:00
|
|
|
return true;
|
2018-04-03 18:24:31 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 19:48:43 +00:00
|
|
|
std::vector<Scope> ComputeScopes(const Form &form) {
|
|
|
|
auto result = std::vector<Scope>();
|
2018-04-03 18:24:31 +00:00
|
|
|
const auto findValue = [&](const Value::Type type) {
|
|
|
|
const auto i = form.values.find(type);
|
|
|
|
Assert(i != form.values.end());
|
|
|
|
return &i->second;
|
|
|
|
};
|
2018-08-12 19:48:43 +00:00
|
|
|
for (const auto &requested : form.request) {
|
|
|
|
Assert(!requested.empty());
|
|
|
|
const auto scopeType = ScopeTypeForValueType(requested[0]);
|
|
|
|
const auto detailsType = DetailsTypeForScopeType(scopeType);
|
|
|
|
const auto ownsDetails = (scopeType != Scope::Type::Identity
|
|
|
|
&& scopeType != Scope::Type::Address);
|
|
|
|
const auto inlineDetails = InlineDetails(form.request, detailsType);
|
|
|
|
if (ownsDetails && inlineDetails) {
|
2018-04-03 18:24:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-08-12 19:48:43 +00:00
|
|
|
result.push_back(Scope(scopeType));
|
|
|
|
auto &scope = result.back();
|
|
|
|
scope.details = (ownsDetails || inlineDetails)
|
|
|
|
? findValue(detailsType)
|
|
|
|
: nullptr;
|
|
|
|
if (ownsDetails) {
|
|
|
|
Assert(requested.size() == 1);
|
|
|
|
} else {
|
|
|
|
for (const auto type : requested) {
|
|
|
|
scope.documents.push_back(findValue(type));
|
|
|
|
}
|
|
|
|
}
|
2018-04-03 18:24:31 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-06-28 19:01:26 +00:00
|
|
|
QString JoinScopeRowReadyString(
|
|
|
|
std::vector<std::pair<QString, QString>> &&values) {
|
|
|
|
using Pair = std::pair<QString, QString>;
|
|
|
|
|
|
|
|
if (values.empty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
auto result = QString();
|
|
|
|
auto size = ranges::accumulate(
|
|
|
|
values,
|
|
|
|
0,
|
|
|
|
ranges::plus(),
|
|
|
|
[](const Pair &v) { return v.second.size(); });
|
|
|
|
result.reserve(size + (values.size() - 1) * 2);
|
|
|
|
for (const auto &pair : values) {
|
|
|
|
if (pair.second.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!result.isEmpty()) {
|
|
|
|
result.append(", ");
|
|
|
|
}
|
|
|
|
result.append(pair.second);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-08-17 12:07:41 +00:00
|
|
|
ScopeRow DocumentRowByType(Value::Type type) {
|
|
|
|
using Type = Value::Type;
|
|
|
|
switch (type) {
|
|
|
|
case Type::Passport:
|
|
|
|
return {
|
|
|
|
lang(lng_passport_identity_passport),
|
|
|
|
lang(lng_passport_identity_passport_upload),
|
|
|
|
};
|
|
|
|
case Type::DriverLicense:
|
|
|
|
return {
|
|
|
|
lang(lng_passport_identity_license),
|
|
|
|
lang(lng_passport_identity_license_upload),
|
|
|
|
};
|
|
|
|
case Type::IdentityCard:
|
|
|
|
return {
|
|
|
|
lang(lng_passport_identity_card),
|
|
|
|
lang(lng_passport_identity_card_upload),
|
|
|
|
};
|
|
|
|
case Type::InternalPassport:
|
|
|
|
return {
|
|
|
|
lang(lng_passport_identity_internal),
|
|
|
|
lang(lng_passport_identity_internal_upload),
|
|
|
|
};
|
|
|
|
case Type::BankStatement:
|
|
|
|
return {
|
|
|
|
lang(lng_passport_address_statement),
|
|
|
|
lang(lng_passport_address_statement_upload),
|
|
|
|
};
|
|
|
|
case Type::UtilityBill:
|
|
|
|
return {
|
|
|
|
lang(lng_passport_address_bill),
|
|
|
|
lang(lng_passport_address_bill_upload),
|
|
|
|
};
|
|
|
|
case Type::RentalAgreement:
|
|
|
|
return {
|
|
|
|
lang(lng_passport_address_agreement),
|
|
|
|
lang(lng_passport_address_agreement_upload),
|
|
|
|
};
|
|
|
|
case Type::PassportRegistration:
|
|
|
|
return {
|
|
|
|
lang(lng_passport_address_registration),
|
|
|
|
lang(lng_passport_address_registration_upload),
|
|
|
|
};
|
|
|
|
case Type::TemporaryRegistration:
|
|
|
|
return {
|
|
|
|
lang(lng_passport_address_temporary),
|
|
|
|
lang(lng_passport_address_temporary_upload),
|
|
|
|
};
|
|
|
|
default: Unexpected("Value type in DocumentRowByType.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString DocumentName(Value::Type type) {
|
|
|
|
return DocumentRowByType(type).title;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopeRow DocumentsOneOfRow(
|
|
|
|
const Scope &scope,
|
|
|
|
const QString &severalTitle,
|
|
|
|
const QString &severalDescription) {
|
|
|
|
Expects(!scope.documents.empty());
|
|
|
|
|
|
|
|
const auto &documents = scope.documents;
|
|
|
|
if (documents.size() == 1) {
|
|
|
|
const auto type = documents.front()->type;
|
|
|
|
return DocumentRowByType(type);
|
|
|
|
} else if (documents.size() == 2) {
|
|
|
|
const auto type1 = documents.front()->type;
|
|
|
|
const auto type2 = documents.back()->type;
|
|
|
|
return {
|
|
|
|
lng_passport_or_title(
|
|
|
|
lt_document,
|
|
|
|
DocumentName(type1),
|
|
|
|
lt_second_document,
|
|
|
|
DocumentName(type2)),
|
|
|
|
severalDescription,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
severalTitle,
|
|
|
|
severalDescription,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-12 15:45:04 +00:00
|
|
|
QString ComputeScopeRowReadyString(const Scope &scope) {
|
|
|
|
switch (scope.type) {
|
2018-08-12 19:48:43 +00:00
|
|
|
case Scope::Type::PersonalDetails:
|
2018-04-12 15:45:04 +00:00
|
|
|
case Scope::Type::Identity:
|
2018-08-12 19:48:43 +00:00
|
|
|
case Scope::Type::AddressDetails:
|
2018-04-12 15:45:04 +00:00
|
|
|
case Scope::Type::Address: {
|
2018-06-28 19:01:26 +00:00
|
|
|
auto list = std::vector<std::pair<QString, QString>>();
|
|
|
|
const auto pushListValue = [&](
|
|
|
|
const QString &key,
|
|
|
|
const QString &value,
|
|
|
|
const QString &keyForAttachmentTo = QString()) {
|
|
|
|
if (keyForAttachmentTo.isEmpty()) {
|
|
|
|
list.push_back({ key, value.trimmed() });
|
|
|
|
} else {
|
|
|
|
const auto i = ranges::find(
|
|
|
|
list,
|
|
|
|
keyForAttachmentTo,
|
|
|
|
[](const std::pair<QString, QString> &value) {
|
2018-08-14 06:42:06 +00:00
|
|
|
return value.first;
|
|
|
|
});
|
2018-06-28 19:01:26 +00:00
|
|
|
Assert(i != end(list));
|
2018-08-14 06:42:06 +00:00
|
|
|
if (const auto data = value.trimmed(); !data.isEmpty()) {
|
|
|
|
if (i->second.isEmpty()) {
|
|
|
|
i->second = data;
|
|
|
|
} else {
|
|
|
|
i->second += ' ' + data;
|
|
|
|
}
|
2018-06-28 19:01:26 +00:00
|
|
|
}
|
2018-04-13 18:14:14 +00:00
|
|
|
}
|
|
|
|
};
|
2018-08-12 19:48:43 +00:00
|
|
|
const auto fields = scope.details
|
|
|
|
? &scope.details->data.parsed.fields
|
|
|
|
: nullptr;
|
2018-04-12 15:45:04 +00:00
|
|
|
const auto document = [&]() -> const Value* {
|
|
|
|
for (const auto &document : scope.documents) {
|
2018-08-12 19:48:43 +00:00
|
|
|
if (document->scansAreFilled()) {
|
2018-04-12 15:45:04 +00:00
|
|
|
return document;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}();
|
2018-08-14 15:27:47 +00:00
|
|
|
if (!scope.documents.empty() && !document) {
|
|
|
|
return QString();
|
|
|
|
}
|
2018-08-14 12:51:12 +00:00
|
|
|
if ((document && scope.documents.size() > 1)
|
|
|
|
|| (!scope.details
|
|
|
|
&& (ScopeTypeForValueType(document->type)
|
|
|
|
== Scope::Type::Address))) {
|
2018-08-17 12:07:41 +00:00
|
|
|
pushListValue("_type", DocumentName(document->type));
|
2018-04-12 15:45:04 +00:00
|
|
|
}
|
2018-08-14 12:51:12 +00:00
|
|
|
const auto scheme = GetDocumentScheme(
|
|
|
|
scope.type,
|
2018-09-21 16:28:46 +00:00
|
|
|
document ? base::make_optional(document->type) : std::nullopt,
|
2018-08-14 12:51:12 +00:00
|
|
|
scope.details ? scope.details->nativeNames : false);
|
2018-08-22 14:02:06 +00:00
|
|
|
using ValueClass = EditDocumentScheme::ValueClass;
|
|
|
|
const auto skipAdditional = [&] {
|
|
|
|
if (!fields) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (const auto &row : scheme.rows) {
|
|
|
|
if (row.valueClass == ValueClass::Additional) {
|
|
|
|
const auto i = fields->find(row.key);
|
|
|
|
const auto native = (i == end(*fields))
|
|
|
|
? QString()
|
|
|
|
: i->second.text;
|
|
|
|
const auto j = fields->find(row.additionalFallbackKey);
|
|
|
|
const auto latin = (j == end(*fields))
|
|
|
|
? QString()
|
|
|
|
: j->second.text;
|
|
|
|
if (latin != native) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}();
|
2018-04-12 15:45:04 +00:00
|
|
|
for (const auto &row : scheme.rows) {
|
|
|
|
const auto format = row.format;
|
2018-08-22 14:02:06 +00:00
|
|
|
if (row.valueClass != ValueClass::Scans) {
|
2018-08-12 19:48:43 +00:00
|
|
|
if (!fields) {
|
|
|
|
continue;
|
2018-08-22 14:02:06 +00:00
|
|
|
} else if (row.valueClass == ValueClass::Additional
|
|
|
|
&& skipAdditional) {
|
|
|
|
continue;
|
2018-08-12 19:48:43 +00:00
|
|
|
}
|
|
|
|
const auto i = fields->find(row.key);
|
2018-08-22 14:02:06 +00:00
|
|
|
const auto text = (i == end(*fields))
|
|
|
|
? QString()
|
|
|
|
: i->second.text;
|
2018-05-15 13:35:59 +00:00
|
|
|
if (row.error && row.error(text).has_value()) {
|
2018-04-12 15:45:04 +00:00
|
|
|
return QString();
|
|
|
|
}
|
2018-06-28 19:01:26 +00:00
|
|
|
pushListValue(
|
|
|
|
row.key,
|
|
|
|
format ? format(text) : text,
|
|
|
|
row.keyForAttachmentTo);
|
2018-04-15 15:06:53 +00:00
|
|
|
} else if (scope.documents.empty()) {
|
|
|
|
continue;
|
2018-04-12 15:45:04 +00:00
|
|
|
} else {
|
|
|
|
const auto i = document->data.parsed.fields.find(row.key);
|
2018-08-22 14:02:06 +00:00
|
|
|
const auto text = (i == end(document->data.parsed.fields))
|
|
|
|
? QString()
|
|
|
|
: i->second.text;
|
2018-05-15 13:35:59 +00:00
|
|
|
if (row.error && row.error(text).has_value()) {
|
2018-04-12 15:45:04 +00:00
|
|
|
return QString();
|
|
|
|
}
|
2018-06-28 19:01:26 +00:00
|
|
|
pushListValue(row.key, text, row.keyForAttachmentTo);
|
2018-04-12 15:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-28 19:01:26 +00:00
|
|
|
return JoinScopeRowReadyString(std::move(list));
|
2018-04-12 15:45:04 +00:00
|
|
|
} break;
|
|
|
|
case Scope::Type::Phone:
|
|
|
|
case Scope::Type::Email: {
|
2018-08-12 19:48:43 +00:00
|
|
|
Assert(scope.details != nullptr);
|
2018-04-12 15:45:04 +00:00
|
|
|
const auto format = GetContactScheme(scope.type).format;
|
2018-08-12 19:48:43 +00:00
|
|
|
const auto &fields = scope.details->data.parsed.fields;
|
2018-04-12 15:45:04 +00:00
|
|
|
const auto i = fields.find("value");
|
|
|
|
return (i != end(fields))
|
2018-04-15 15:06:53 +00:00
|
|
|
? (format ? format(i->second.text) : i->second.text)
|
2018-04-12 15:45:04 +00:00
|
|
|
: QString();
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
Unexpected("Scope type in ComputeScopeRowReadyString.");
|
|
|
|
}
|
|
|
|
|
|
|
|
ScopeRow ComputeScopeRow(const Scope &scope) {
|
2018-08-14 12:51:12 +00:00
|
|
|
const auto addReadyError = [&](
|
|
|
|
ScopeRow &&row,
|
|
|
|
QString titleFallback = QString()) {
|
|
|
|
row.ready = ComputeScopeRowReadyString(scope);
|
2018-04-17 17:54:52 +00:00
|
|
|
auto errors = QStringList();
|
|
|
|
const auto addValueErrors = [&](not_null<const Value*> value) {
|
2018-08-12 19:48:43 +00:00
|
|
|
if (!value->error.isEmpty()) {
|
|
|
|
errors.push_back(value->error);
|
|
|
|
}
|
2018-08-14 15:27:47 +00:00
|
|
|
const auto addTypeErrors = [&](FileType type) {
|
|
|
|
if (!value->fileMissingError(type).isEmpty()) {
|
|
|
|
errors.push_back(value->fileMissingError(type));
|
2018-04-17 17:54:52 +00:00
|
|
|
}
|
2018-08-14 15:27:47 +00:00
|
|
|
for (const auto &scan : value->files(type)) {
|
|
|
|
if (!scan.error.isEmpty()) {
|
|
|
|
errors.push_back(scan.error);
|
|
|
|
}
|
2018-05-11 22:55:56 +00:00
|
|
|
}
|
2018-08-14 15:27:47 +00:00
|
|
|
};
|
|
|
|
addTypeErrors(FileType::Scan);
|
|
|
|
addTypeErrors(FileType::Translation);
|
2018-08-12 19:48:43 +00:00
|
|
|
for (const auto &[type, scan] : value->specialScans) {
|
|
|
|
if (!scan.error.isEmpty()) {
|
|
|
|
errors.push_back(scan.error);
|
|
|
|
}
|
2018-04-17 17:54:52 +00:00
|
|
|
}
|
|
|
|
for (const auto &[key, value] : value->data.parsed.fields) {
|
|
|
|
if (!value.error.isEmpty()) {
|
|
|
|
errors.push_back(value.error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-08-03 21:48:00 +00:00
|
|
|
const auto document = [&]() -> const Value* {
|
|
|
|
for (const auto &document : scope.documents) {
|
2018-08-12 19:48:43 +00:00
|
|
|
if (document->scansAreFilled()) {
|
2018-08-03 21:48:00 +00:00
|
|
|
return document;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}();
|
|
|
|
if (document) {
|
|
|
|
addValueErrors(document);
|
|
|
|
}
|
2018-08-12 19:48:43 +00:00
|
|
|
if (scope.details) {
|
|
|
|
addValueErrors(scope.details);
|
2018-07-10 20:25:40 +00:00
|
|
|
}
|
2018-08-12 19:48:43 +00:00
|
|
|
if (!errors.isEmpty()) {
|
|
|
|
row.error = errors[0];// errors.join('\n');
|
2018-08-14 12:51:12 +00:00
|
|
|
} else if (row.title == row.ready && !titleFallback.isEmpty()) {
|
|
|
|
row.title = titleFallback;
|
2018-07-10 09:50:11 +00:00
|
|
|
}
|
2018-08-14 12:51:12 +00:00
|
|
|
|
2018-08-17 14:59:07 +00:00
|
|
|
if (row.error.isEmpty()
|
|
|
|
&& row.ready.isEmpty()
|
|
|
|
&& !scope.documents.empty()) {
|
|
|
|
if (document) {
|
|
|
|
row.description = (scope.type == Scope::Type::Identity)
|
|
|
|
? lang(lng_passport_personal_details_enter)
|
|
|
|
: lang(lng_passport_address_enter);
|
|
|
|
} else {
|
|
|
|
const auto best = ranges::min(
|
|
|
|
scope.documents,
|
|
|
|
std::less<>(),
|
|
|
|
[](not_null<const Value*> document) {
|
|
|
|
return document->whatNotFilled();
|
|
|
|
});
|
|
|
|
const auto notFilled = best->whatNotFilled();
|
|
|
|
if (notFilled & Value::kNoTranslationFilled) {
|
|
|
|
row.description = lang(lng_passport_translation_needed);
|
|
|
|
} else if (notFilled & Value::kNoSelfieFilled) {
|
|
|
|
row.description = lang(lng_passport_identity_selfie);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 17:42:28 +00:00
|
|
|
return row;
|
|
|
|
};
|
2018-04-12 15:45:04 +00:00
|
|
|
switch (scope.type) {
|
2018-08-12 19:48:43 +00:00
|
|
|
case Scope::Type::PersonalDetails:
|
|
|
|
return addReadyError({
|
|
|
|
lang(lng_passport_personal_details),
|
|
|
|
lang(lng_passport_personal_details_enter),
|
|
|
|
});
|
2018-04-12 15:45:04 +00:00
|
|
|
case Scope::Type::Identity:
|
2018-08-17 12:07:41 +00:00
|
|
|
return addReadyError(DocumentsOneOfRow(
|
|
|
|
scope,
|
2018-04-12 15:45:04 +00:00
|
|
|
lang(lng_passport_identity_title),
|
2018-08-17 12:07:41 +00:00
|
|
|
lang(lng_passport_identity_description)));
|
2018-08-12 19:48:43 +00:00
|
|
|
case Scope::Type::AddressDetails:
|
|
|
|
return addReadyError({
|
|
|
|
lang(lng_passport_address),
|
|
|
|
lang(lng_passport_address_enter),
|
2018-08-14 12:51:12 +00:00
|
|
|
});
|
2018-08-12 19:48:43 +00:00
|
|
|
case Scope::Type::Address:
|
2018-08-17 12:07:41 +00:00
|
|
|
return addReadyError(DocumentsOneOfRow(
|
|
|
|
scope,
|
2018-04-12 15:45:04 +00:00
|
|
|
lang(lng_passport_address_title),
|
2018-08-17 12:07:41 +00:00
|
|
|
lang(lng_passport_address_description)));
|
2018-04-12 15:45:04 +00:00
|
|
|
case Scope::Type::Phone:
|
2018-04-13 17:42:28 +00:00
|
|
|
return addReadyError({
|
2018-04-12 15:45:04 +00:00
|
|
|
lang(lng_passport_phone_title),
|
|
|
|
lang(lng_passport_phone_description),
|
2018-04-13 17:42:28 +00:00
|
|
|
});
|
2018-04-12 15:45:04 +00:00
|
|
|
case Scope::Type::Email:
|
2018-04-13 17:42:28 +00:00
|
|
|
return addReadyError({
|
2018-04-12 15:45:04 +00:00
|
|
|
lang(lng_passport_email_title),
|
|
|
|
lang(lng_passport_email_description),
|
2018-04-13 17:42:28 +00:00
|
|
|
});
|
2018-04-12 15:45:04 +00:00
|
|
|
default: Unexpected("Scope type in ComputeScopeRow.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-03 18:24:31 +00:00
|
|
|
} // namespace Passport
|