mirror of
https://github.com/vale981/tdesktop
synced 2025-03-05 09:41:41 -05:00
Better display of first_name + last_name.
This commit is contained in:
parent
49ea9434f2
commit
e64d102efd
3 changed files with 55 additions and 8 deletions
|
@ -101,14 +101,56 @@ std::vector<Scope> ComputeScopes(
|
|||
return result;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
QString ComputeScopeRowReadyString(const Scope &scope) {
|
||||
switch (scope.type) {
|
||||
case Scope::Type::Identity:
|
||||
case Scope::Type::Address: {
|
||||
auto list = QStringList();
|
||||
const auto pushListValue = [&](const QString &value) {
|
||||
if (const auto trimmed = value.trimmed(); !trimmed.isEmpty()) {
|
||||
list.push_back(trimmed);
|
||||
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) {
|
||||
return value.first;
|
||||
});
|
||||
Assert(i != end(list));
|
||||
if (i->second.isEmpty()) {
|
||||
i->second = value.trimmed();
|
||||
} else {
|
||||
i->second += ' ' + value.trimmed();
|
||||
}
|
||||
}
|
||||
};
|
||||
const auto &fields = scope.fields->data.parsed.fields;
|
||||
|
@ -121,7 +163,7 @@ QString ComputeScopeRowReadyString(const Scope &scope) {
|
|||
return nullptr;
|
||||
}();
|
||||
if (document && scope.documents.size() > 1) {
|
||||
pushListValue([&] {
|
||||
pushListValue("_type", [&] {
|
||||
using Type = Value::Type;
|
||||
switch (document->type) {
|
||||
case Type::Passport:
|
||||
|
@ -161,7 +203,10 @@ QString ComputeScopeRowReadyString(const Scope &scope) {
|
|||
if (row.error && row.error(text).has_value()) {
|
||||
return QString();
|
||||
}
|
||||
pushListValue(format ? format(text) : text);
|
||||
pushListValue(
|
||||
row.key,
|
||||
format ? format(text) : text,
|
||||
row.keyForAttachmentTo);
|
||||
} else if (scope.documents.empty()) {
|
||||
continue;
|
||||
} else {
|
||||
|
@ -173,10 +218,10 @@ QString ComputeScopeRowReadyString(const Scope &scope) {
|
|||
if (row.error && row.error(text).has_value()) {
|
||||
return QString();
|
||||
}
|
||||
pushListValue(text);
|
||||
pushListValue(row.key, text, row.keyForAttachmentTo);
|
||||
}
|
||||
}
|
||||
return list.join(", ");
|
||||
return JoinScopeRowReadyString(std::move(list));
|
||||
} break;
|
||||
case Scope::Type::Phone:
|
||||
case Scope::Type::Email: {
|
||||
|
|
|
@ -138,6 +138,7 @@ EditDocumentScheme GetDocumentScheme(
|
|||
NameValidate,
|
||||
DontFormat,
|
||||
kMaxNameSize,
|
||||
qsl("first_name")
|
||||
},
|
||||
{
|
||||
ValueClass::Fields,
|
||||
|
|
|
@ -46,6 +46,7 @@ struct EditDocumentScheme {
|
|||
Fn<base::optional<QString>(const QString &value)> error;
|
||||
Fn<QString(const QString &value)> format;
|
||||
int lengthLimit = 0;
|
||||
QString keyForAttachmentTo; // attach last_name to first_name
|
||||
};
|
||||
std::vector<Row> rows;
|
||||
QString rowsHeader;
|
||||
|
|
Loading…
Add table
Reference in a new issue