Fix native names handling in passport.

This commit is contained in:
John Preston 2018-08-22 17:02:06 +03:00
parent ec61aa0080
commit 83fcb8e8ed
2 changed files with 61 additions and 22 deletions

View File

@ -1222,31 +1222,51 @@ void FormController::fillErrors() {
}
void FormController::fillNativeFromFallback() {
// Check if additional values (*_name_native) were requested.
const auto i = _form.values.find(Value::Type::PersonalDetails);
if (i == end(_form.values) || !i->second.nativeNames) {
return;
}
auto values = i->second.data.parsed;
// Check if additional values should be copied from fallback values.
const auto scheme = GetDocumentScheme(
Scope::Type::PersonalDetails,
base::none,
true);
const auto dependencyIt = values.fields.find(
scheme.additionalDependencyKey);
const auto dependency = (dependencyIt == end(values.fields))
? QString()
: dependencyIt->second.text;
if (scheme.additionalShown(dependency)
!= EditDocumentScheme::AdditionalVisibility::OnlyIfError) {
return;
}
// Copy additional values from fallback if they're not filled yet.
auto changed = false;
auto values = i->second.data.parsed;
using Scheme = EditDocumentScheme;
for (const auto &row : scheme.rows) {
if (row.valueClass == Scheme::ValueClass::Additional) {
auto &field = values.fields[row.key];
if (!field.text.isEmpty() || !field.error.isEmpty()) {
const auto nativeIt = values.fields.find(row.key);
const auto native = (nativeIt == end(values.fields))
? QString()
: nativeIt->second.text;
if (!native.isEmpty()
|| (nativeIt != end(values.fields)
&& !nativeIt->second.error.isEmpty())) {
return;
}
const auto i = values.fields.find(row.additionalFallbackKey);
const auto value = (i == end(values.fields))
const auto latinIt = values.fields.find(
row.additionalFallbackKey);
const auto latin = (latinIt == end(values.fields))
? QString()
: i->second.text;
if (row.error(value).has_value()) {
: latinIt->second.text;
if (row.error(latin).has_value()) {
return;
} else if (field.text != value) {
field.text = value;
} else if (native != latin) {
values.fields[row.key].text = latin;
changed = true;
}
}
@ -2461,10 +2481,6 @@ void FormController::formDone(const MTPaccount_AuthorizationForm &result) {
}
void FormController::requestConfig() {
const auto i = _form.values.find(Value::Type::PersonalDetails);
if (i == end(_form.values) || !i->second.nativeNames) {
return;
}
const auto hash = ConfigInstance().hash;
_configRequestId = request(MTPhelp_GetPassportConfig(
MTP_int(hash)

View File

@ -378,17 +378,41 @@ QString ComputeScopeRowReadyString(const Scope &scope) {
scope.type,
document ? base::make_optional(document->type) : base::none,
scope.details ? scope.details->nativeNames : false);
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;
}();
for (const auto &row : scheme.rows) {
const auto format = row.format;
if (row.valueClass != EditDocumentScheme::ValueClass::Scans) {
if (row.valueClass != ValueClass::Scans) {
if (!fields) {
continue;
} else if (row.valueClass == ValueClass::Additional
&& skipAdditional) {
continue;
}
const auto i = fields->find(row.key);
if (i == end(*fields)) {
return QString();
}
const auto text = i->second.text;
const auto text = (i == end(*fields))
? QString()
: i->second.text;
if (row.error && row.error(text).has_value()) {
return QString();
}
@ -400,10 +424,9 @@ QString ComputeScopeRowReadyString(const Scope &scope) {
continue;
} else {
const auto i = document->data.parsed.fields.find(row.key);
if (i == end(document->data.parsed.fields)) {
return QString();
}
const auto text = i->second.text;
const auto text = (i == end(document->data.parsed.fields))
? QString()
: i->second.text;
if (row.error && row.error(text).has_value()) {
return QString();
}