Fix native names handling in passport.
This commit is contained in:
		
							parent
							
								
									ec61aa0080
								
							
						
					
					
						commit
						83fcb8e8ed
					
				
					 2 changed files with 61 additions and 22 deletions
				
			
		| 
						 | 
					@ -1222,31 +1222,51 @@ void FormController::fillErrors() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void FormController::fillNativeFromFallback() {
 | 
					void FormController::fillNativeFromFallback() {
 | 
				
			||||||
 | 
						// Check if additional values (*_name_native) were requested.
 | 
				
			||||||
	const auto i = _form.values.find(Value::Type::PersonalDetails);
 | 
						const auto i = _form.values.find(Value::Type::PersonalDetails);
 | 
				
			||||||
	if (i == end(_form.values) || !i->second.nativeNames) {
 | 
						if (i == end(_form.values) || !i->second.nativeNames) {
 | 
				
			||||||
		return;
 | 
							return;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						auto values = i->second.data.parsed;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Check if additional values should be copied from fallback values.
 | 
				
			||||||
	const auto scheme = GetDocumentScheme(
 | 
						const auto scheme = GetDocumentScheme(
 | 
				
			||||||
		Scope::Type::PersonalDetails,
 | 
							Scope::Type::PersonalDetails,
 | 
				
			||||||
		base::none,
 | 
							base::none,
 | 
				
			||||||
		true);
 | 
							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 changed = false;
 | 
				
			||||||
	auto values = i->second.data.parsed;
 | 
					 | 
				
			||||||
	using Scheme = EditDocumentScheme;
 | 
						using Scheme = EditDocumentScheme;
 | 
				
			||||||
	for (const auto &row : scheme.rows) {
 | 
						for (const auto &row : scheme.rows) {
 | 
				
			||||||
		if (row.valueClass == Scheme::ValueClass::Additional) {
 | 
							if (row.valueClass == Scheme::ValueClass::Additional) {
 | 
				
			||||||
			auto &field = values.fields[row.key];
 | 
								const auto nativeIt = values.fields.find(row.key);
 | 
				
			||||||
			if (!field.text.isEmpty() || !field.error.isEmpty()) {
 | 
								const auto native = (nativeIt == end(values.fields))
 | 
				
			||||||
 | 
									? QString()
 | 
				
			||||||
 | 
									: nativeIt->second.text;
 | 
				
			||||||
 | 
								if (!native.isEmpty()
 | 
				
			||||||
 | 
									|| (nativeIt != end(values.fields)
 | 
				
			||||||
 | 
										&& !nativeIt->second.error.isEmpty())) {
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			const auto i = values.fields.find(row.additionalFallbackKey);
 | 
								const auto latinIt = values.fields.find(
 | 
				
			||||||
			const auto value = (i == end(values.fields))
 | 
									row.additionalFallbackKey);
 | 
				
			||||||
 | 
								const auto latin = (latinIt == end(values.fields))
 | 
				
			||||||
				? QString()
 | 
									? QString()
 | 
				
			||||||
				: i->second.text;
 | 
									: latinIt->second.text;
 | 
				
			||||||
			if (row.error(value).has_value()) {
 | 
								if (row.error(latin).has_value()) {
 | 
				
			||||||
				return;
 | 
									return;
 | 
				
			||||||
			} else if (field.text != value) {
 | 
								} else if (native != latin) {
 | 
				
			||||||
				field.text = value;
 | 
									values.fields[row.key].text = latin;
 | 
				
			||||||
				changed = true;
 | 
									changed = true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -2461,10 +2481,6 @@ void FormController::formDone(const MTPaccount_AuthorizationForm &result) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void FormController::requestConfig() {
 | 
					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;
 | 
						const auto hash = ConfigInstance().hash;
 | 
				
			||||||
	_configRequestId = request(MTPhelp_GetPassportConfig(
 | 
						_configRequestId = request(MTPhelp_GetPassportConfig(
 | 
				
			||||||
		MTP_int(hash)
 | 
							MTP_int(hash)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -378,17 +378,41 @@ QString ComputeScopeRowReadyString(const Scope &scope) {
 | 
				
			||||||
			scope.type,
 | 
								scope.type,
 | 
				
			||||||
			document ? base::make_optional(document->type) : base::none,
 | 
								document ? base::make_optional(document->type) : base::none,
 | 
				
			||||||
			scope.details ? scope.details->nativeNames : false);
 | 
								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) {
 | 
							for (const auto &row : scheme.rows) {
 | 
				
			||||||
			const auto format = row.format;
 | 
								const auto format = row.format;
 | 
				
			||||||
			if (row.valueClass != EditDocumentScheme::ValueClass::Scans) {
 | 
								if (row.valueClass != ValueClass::Scans) {
 | 
				
			||||||
				if (!fields) {
 | 
									if (!fields) {
 | 
				
			||||||
					continue;
 | 
										continue;
 | 
				
			||||||
 | 
									} else if (row.valueClass == ValueClass::Additional
 | 
				
			||||||
 | 
										&& skipAdditional) {
 | 
				
			||||||
 | 
										continue;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				const auto i = fields->find(row.key);
 | 
									const auto i = fields->find(row.key);
 | 
				
			||||||
				if (i == end(*fields)) {
 | 
									const auto text = (i == end(*fields))
 | 
				
			||||||
					return QString();
 | 
										? QString()
 | 
				
			||||||
				}
 | 
										: i->second.text;
 | 
				
			||||||
				const auto text = i->second.text;
 | 
					 | 
				
			||||||
				if (row.error && row.error(text).has_value()) {
 | 
									if (row.error && row.error(text).has_value()) {
 | 
				
			||||||
					return QString();
 | 
										return QString();
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					@ -400,10 +424,9 @@ QString ComputeScopeRowReadyString(const Scope &scope) {
 | 
				
			||||||
				continue;
 | 
									continue;
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				const auto i = document->data.parsed.fields.find(row.key);
 | 
									const auto i = document->data.parsed.fields.find(row.key);
 | 
				
			||||||
				if (i == end(document->data.parsed.fields)) {
 | 
									const auto text = (i == end(document->data.parsed.fields))
 | 
				
			||||||
					return QString();
 | 
										? QString()
 | 
				
			||||||
				}
 | 
										: i->second.text;
 | 
				
			||||||
				const auto text = i->second.text;
 | 
					 | 
				
			||||||
				if (row.error && row.error(text).has_value()) {
 | 
									if (row.error && row.error(text).has_value()) {
 | 
				
			||||||
					return QString();
 | 
										return QString();
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue