2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Use getters in MTP classes.

This commit is contained in:
John Preston
2019-07-05 15:38:38 +02:00
parent 3ca28c0cf9
commit 567bf60644
100 changed files with 2807 additions and 2672 deletions

View File

@@ -143,14 +143,14 @@ void CollectToRequestedRow(
RequestedRow &row,
const MTPSecureRequiredType &data) {
data.match([&](const MTPDsecureRequiredType &data) {
row.values.emplace_back(ConvertType(data.vtype));
row.values.emplace_back(ConvertType(data.vtype()));
auto &value = row.values.back();
value.selfieRequired = data.is_selfie_required();
value.translationRequired = data.is_translation_required();
value.nativeNames = data.is_native_names();
}, [&](const MTPDsecureRequiredTypeOneOf &data) {
row.values.reserve(row.values.size() + data.vtypes.v.size());
for (const auto &one : data.vtypes.v) {
row.values.reserve(row.values.size() + data.vtypes().v.size());
for (const auto &one : data.vtypes().v) {
CollectToRequestedRow(row, one);
}
});
@@ -239,10 +239,10 @@ Config &ConfigInstance() {
Config ParseConfig(const MTPhelp_PassportConfig &data) {
return data.match([](const MTPDhelp_passportConfig &data) {
auto result = Config();
result.hash = data.vhash.v;
result.hash = data.vhash().v;
auto error = QJsonParseError{ 0, QJsonParseError::NoError };
const auto document = QJsonDocument::fromJson(
data.vcountries_langs.c_dataJSON().vdata.v,
data.vcountries_langs().c_dataJSON().vdata().v,
&error);
if (error.error != QJsonParseError::NoError) {
LOG(("API Error: Failed to parse passport config, error: %1."
@@ -843,12 +843,11 @@ void FormController::submitPassword(
_passwordCheckRequestId = 0;
_savedPasswordValue = QByteArray();
const auto &data = result.c_account_passwordSettings();
_password.confirmedEmail = qs(data.vemail);
if (data.has_secure_settings()) {
const auto &wrapped = data.vsecure_settings;
const auto &settings = wrapped.c_secureSecretSettings();
_password.confirmedEmail = qs(data.vemail().value_or_empty());
if (const auto wrapped = data.vsecure_settings()) {
const auto &settings = wrapped->c_secureSecretSettings();
const auto algo = Core::ParseSecureSecretAlgo(
settings.vsecure_algo);
settings.vsecure_algo());
if (!algo) {
_view->showUpdateAppBox();
return;
@@ -857,10 +856,10 @@ void FormController::submitPassword(
algo,
bytes::make_span(password));
validateSecureSecret(
bytes::make_span(settings.vsecure_secret.v),
bytes::make_span(settings.vsecure_secret().v),
hashForSecret,
bytes::make_span(password),
settings.vsecure_secret_id.v);
settings.vsecure_secret_id().v);
if (!_secret.empty()) {
auto saved = SavedCredentials();
saved.hashForAuth = base::take(_passwordCheckHash);
@@ -935,22 +934,21 @@ void FormController::checkSavedPasswordSettings(
_passwordCheckRequestId = 0;
const auto &data = result.c_account_passwordSettings();
if (data.has_secure_settings()) {
const auto &wrapped = data.vsecure_settings;
const auto &settings = wrapped.c_secureSecretSettings();
if (const auto wrapped = data.vsecure_settings()) {
const auto &settings = wrapped->c_secureSecretSettings();
const auto algo = Core::ParseSecureSecretAlgo(
settings.vsecure_algo);
settings.vsecure_algo());
if (!algo) {
_view->showUpdateAppBox();
return;
} else if (!settings.vsecure_secret.v.isEmpty()
&& settings.vsecure_secret_id.v == credentials.secretId) {
_password.confirmedEmail = qs(data.vemail);
} else if (!settings.vsecure_secret().v.isEmpty()
&& settings.vsecure_secret_id().v == credentials.secretId) {
_password.confirmedEmail = qs(data.vemail().value_or_empty());
validateSecureSecret(
bytes::make_span(settings.vsecure_secret.v),
bytes::make_span(settings.vsecure_secret().v),
credentials.hashForSecret,
{},
settings.vsecure_secret_id.v);
settings.vsecure_secret_id().v);
}
}
if (_secret.empty()) {
@@ -982,7 +980,7 @@ void FormController::recoverPassword() {
_recoverRequestId = 0;
const auto &data = result.c_auth_passwordRecovery();
const auto pattern = qs(data.vemail_pattern);
const auto pattern = qs(data.vemail_pattern());
const auto box = _view->show(Box<RecoverBox>(
pattern,
_password.notEmptyPassport));
@@ -1096,7 +1094,7 @@ void FormController::resetSecret(
MTPstring(), // email
MTP_secureSecretSettings(
MTP_securePasswordKdfAlgoUnknown(), // secure_algo
MTP_bytes(QByteArray()), // secure_secret
MTP_bytes(), // secure_secret
MTP_long(0))) // secure_secret_id
)).done([=](const MTPBool &result) {
_saveSecretRequestId = 0;
@@ -1145,11 +1143,11 @@ void FormController::fillErrors() {
return nullptr;
};
const auto setSpecialScanError = [&](FileType type, auto &&data) {
if (const auto value = find(data.vtype)) {
if (const auto value = find(data.vtype())) {
if (value->requiresSpecialScan(type)) {
const auto i = value->specialScans.find(type);
if (i != value->specialScans.end()) {
i->second.error = qs(data.vtext);
i->second.error = qs(data.vtext());
} else {
LOG(("API Error: "
"Special scan %1 not found for error value."
@@ -1160,48 +1158,48 @@ void FormController::fillErrors() {
};
for (const auto &error : _form.pendingErrors) {
error.match([&](const MTPDsecureValueError &data) {
if (const auto value = find(data.vtype)) {
if (const auto value = find(data.vtype())) {
if (CanHaveErrors(value->type)) {
value->error = qs(data.vtext);
value->error = qs(data.vtext());
}
}
}, [&](const MTPDsecureValueErrorData &data) {
if (const auto value = find(data.vtype)) {
const auto key = qs(data.vfield);
if (const auto value = find(data.vtype())) {
const auto key = qs(data.vfield());
if (CanHaveErrors(value->type)
&& !SkipFieldCheck(value, key)) {
value->data.parsed.fields[key].error = qs(data.vtext);
value->data.parsed.fields[key].error = qs(data.vtext());
}
}
}, [&](const MTPDsecureValueErrorFile &data) {
const auto hash = bytes::make_span(data.vfile_hash.v);
if (const auto value = find(data.vtype)) {
const auto hash = bytes::make_span(data.vfile_hash().v);
if (const auto value = find(data.vtype())) {
if (const auto file = scan(*value, FileType::Scan, hash)) {
if (value->requiresScan(FileType::Scan)) {
file->error = qs(data.vtext);
file->error = qs(data.vtext());
}
}
}
}, [&](const MTPDsecureValueErrorFiles &data) {
if (const auto value = find(data.vtype)) {
if (const auto value = find(data.vtype())) {
if (value->requiresScan(FileType::Scan)) {
value->fileMissingError(FileType::Scan)
= qs(data.vtext);
= qs(data.vtext());
}
}
}, [&](const MTPDsecureValueErrorTranslationFile &data) {
const auto hash = bytes::make_span(data.vfile_hash.v);
if (const auto value = find(data.vtype)) {
const auto hash = bytes::make_span(data.vfile_hash().v);
if (const auto value = find(data.vtype())) {
const auto file = scan(*value, FileType::Translation, hash);
if (file && value->requiresScan(FileType::Translation)) {
file->error = qs(data.vtext);
file->error = qs(data.vtext());
}
}
}, [&](const MTPDsecureValueErrorTranslationFiles &data) {
if (const auto value = find(data.vtype)) {
if (const auto value = find(data.vtype())) {
if (value->requiresScan(FileType::Translation)) {
value->fileMissingError(FileType::Translation)
= qs(data.vtext);
= qs(data.vtext());
}
}
}, [&](const MTPDsecureValueErrorFrontSide &data) {
@@ -2094,8 +2092,8 @@ void FormController::startPhoneVerification(not_null<Value*> value) {
value->verification.requestId = 0;
const auto &data = result.c_auth_sentCode();
value->verification.phoneCodeHash = qs(data.vphone_code_hash);
switch (data.vtype.type()) {
value->verification.phoneCodeHash = qs(data.vphone_code_hash());
switch (data.vtype().type()) {
case mtpc_auth_sentCodeTypeApp:
LOG(("API Error: sentCodeTypeApp not expected "
"in FormController::startPhoneVerification."));
@@ -2105,33 +2103,32 @@ void FormController::startPhoneVerification(not_null<Value*> value) {
"in FormController::startPhoneVerification."));
return;
case mtpc_auth_sentCodeTypeCall: {
const auto &type = data.vtype.c_auth_sentCodeTypeCall();
value->verification.codeLength = (type.vlength.v > 0)
? type.vlength.v
const auto &type = data.vtype().c_auth_sentCodeTypeCall();
value->verification.codeLength = (type.vlength().v > 0)
? type.vlength().v
: -1;
value->verification.call = std::make_unique<SentCodeCall>(
[=] { requestPhoneCall(value); },
[=] { _verificationUpdate.fire_copy(value); });
value->verification.call->setStatus(
{ SentCodeCall::State::Called, 0 });
if (data.has_next_type()) {
if (data.vnext_type()) {
LOG(("API Error: next_type is not supported for calls."));
}
} break;
case mtpc_auth_sentCodeTypeSms: {
const auto &type = data.vtype.c_auth_sentCodeTypeSms();
value->verification.codeLength = (type.vlength.v > 0)
? type.vlength.v
const auto &type = data.vtype().c_auth_sentCodeTypeSms();
value->verification.codeLength = (type.vlength().v > 0)
? type.vlength().v
: -1;
const auto &next = data.vnext_type;
if (data.has_next_type()
&& next.type() == mtpc_auth_codeTypeCall) {
const auto next = data.vnext_type();
if (next && next->type() == mtpc_auth_codeTypeCall) {
value->verification.call = std::make_unique<SentCodeCall>(
[=] { requestPhoneCall(value); },
[=] { _verificationUpdate.fire_copy(value); });
value->verification.call->setStatus({
SentCodeCall::State::Waiting,
data.has_timeout() ? data.vtimeout.v : 60 });
data.vtimeout().value_or(60) });
}
} break;
}
@@ -2150,8 +2147,8 @@ void FormController::startEmailVerification(not_null<Value*> value) {
value->verification.requestId = 0;
const auto &data = result.c_account_sentEmailCode();
value->verification.codeLength = (data.vlength.v > 0)
? data.vlength.v
value->verification.codeLength = (data.vlength().v > 0)
? data.vlength().v
: -1;
_verificationNeeded.fire_copy(value);
}).fail([=](const RPCError &error) {
@@ -2303,13 +2300,13 @@ auto FormController::parseFile(
case mtpc_secureFile: {
const auto &fields = data.c_secureFile();
auto result = File();
result.id = fields.vid.v;
result.accessHash = fields.vaccess_hash.v;
result.size = fields.vsize.v;
result.date = fields.vdate.v;
result.dcId = fields.vdc_id.v;
result.hash = bytes::make_vector(fields.vfile_hash.v);
result.encryptedSecret = bytes::make_vector(fields.vsecret.v);
result.id = fields.vid().v;
result.accessHash = fields.vaccess_hash().v;
result.size = fields.vsize().v;
result.date = fields.vdate().v;
result.dcId = fields.vdc_id().v;
result.hash = bytes::make_vector(fields.vfile_hash().v);
result.encryptedSecret = bytes::make_vector(fields.vsecret().v);
fillDownloadedFile(result, editData);
return result;
} break;
@@ -2351,22 +2348,22 @@ auto FormController::parseValue(
Expects(value.type() == mtpc_secureValue);
const auto &data = value.c_secureValue();
const auto type = ConvertType(data.vtype);
const auto type = ConvertType(data.vtype());
auto result = Value(type);
result.submitHash = bytes::make_vector(data.vhash.v);
if (data.has_data()) {
Assert(data.vdata.type() == mtpc_secureData);
const auto &fields = data.vdata.c_secureData();
result.data.original = fields.vdata.v;
result.data.hash = bytes::make_vector(fields.vdata_hash.v);
result.data.encryptedSecret = bytes::make_vector(fields.vsecret.v);
result.submitHash = bytes::make_vector(data.vhash().v);
if (const auto secureData = data.vdata()) {
secureData->match([&](const MTPDsecureData &data) {
result.data.original = data.vdata().v;
result.data.hash = bytes::make_vector(data.vdata_hash().v);
result.data.encryptedSecret = bytes::make_vector(data.vsecret().v);
});
}
if (data.has_files()) {
result.files(FileType::Scan) = parseFiles(data.vfiles.v, editData);
if (const auto files = data.vfiles()) {
result.files(FileType::Scan) = parseFiles(files->v, editData);
}
if (data.has_translation()) {
if (const auto translation = data.vtranslation()) {
result.files(FileType::Translation) = parseFiles(
data.vtranslation.v,
translation->v,
editData);
}
const auto parseSpecialScan = [&](
@@ -2376,26 +2373,21 @@ auto FormController::parseValue(
result.specialScans.emplace(type, std::move(*parsed));
}
};
if (data.has_front_side()) {
parseSpecialScan(FileType::FrontSide, data.vfront_side);
if (const auto side = data.vfront_side()) {
parseSpecialScan(FileType::FrontSide, *side);
}
if (data.has_reverse_side()) {
parseSpecialScan(FileType::ReverseSide, data.vreverse_side);
if (const auto side = data.vreverse_side()) {
parseSpecialScan(FileType::ReverseSide, *side);
}
if (data.has_selfie()) {
parseSpecialScan(FileType::Selfie, data.vselfie);
if (const auto selfie = data.vselfie()) {
parseSpecialScan(FileType::Selfie, *selfie);
}
if (data.has_plain_data()) {
switch (data.vplain_data.type()) {
case mtpc_securePlainPhone: {
const auto &fields = data.vplain_data.c_securePlainPhone();
result.data.parsed.fields["value"].text = qs(fields.vphone);
} break;
case mtpc_securePlainEmail: {
const auto &fields = data.vplain_data.c_securePlainEmail();
result.data.parsed.fields["value"].text = qs(fields.vemail);
} break;
}
if (const auto plain = data.vplain_data()) {
plain->match([&](const MTPDsecurePlainPhone &data) {
result.data.parsed.fields["value"].text = qs(data.vphone());
}, [&](const MTPDsecurePlainEmail &data) {
result.data.parsed.fields["value"].text = qs(data.vemail());
});
}
return result;
}
@@ -2494,9 +2486,9 @@ bool FormController::parseForm(const MTPaccount_AuthorizationForm &result) {
const auto &data = result.c_account_authorizationForm();
Auth().data().processUsers(data.vusers);
Auth().data().processUsers(data.vusers());
for (const auto &value : data.vvalues.v) {
for (const auto &value : data.vvalues().v) {
auto parsed = parseValue(value);
const auto type = parsed.type;
const auto alreadyIt = _form.values.find(type);
@@ -2507,10 +2499,10 @@ bool FormController::parseForm(const MTPaccount_AuthorizationForm &result) {
}
_form.values.emplace(type, std::move(parsed));
}
if (data.has_privacy_policy_url()) {
_form.privacyPolicyUrl = qs(data.vprivacy_policy_url);
if (const auto url = data.vprivacy_policy_url()) {
_form.privacyPolicyUrl = qs(*url);
}
for (const auto &required : data.vrequired_types.v) {
for (const auto &required : data.vrequired_types().v) {
const auto row = CollectRequestedRow(required);
for (const auto requested : row.values) {
const auto type = requested.type;
@@ -2529,7 +2521,7 @@ bool FormController::parseForm(const MTPaccount_AuthorizationForm &result) {
return false;
}
_bot = Auth().data().userLoaded(_request.botId);
_form.pendingErrors = data.verrors.v;
_form.pendingErrors = data.verrors().v;
return true;
}
@@ -2608,20 +2600,18 @@ void FormController::showForm() {
bool FormController::applyPassword(const MTPDaccount_password &result) {
auto settings = PasswordSettings();
settings.hint = qs(result.vhint);
settings.hint = qs(result.vhint().value_or_empty());
settings.hasRecovery = result.is_has_recovery();
settings.notEmptyPassport = result.is_has_secure_values();
settings.request = Core::ParseCloudPasswordCheckRequest(result);
settings.unknownAlgo = result.has_current_algo()
&& !settings.request;
settings.unconfirmedPattern = result.has_email_unconfirmed_pattern()
? qs(result.vemail_unconfirmed_pattern)
: QString();
settings.unknownAlgo = result.vcurrent_algo() && !settings.request;
settings.unconfirmedPattern =
qs(result.vemail_unconfirmed_pattern().value_or_empty());
settings.newAlgo = Core::ValidateNewCloudPasswordAlgo(
Core::ParseCloudPasswordAlgo(result.vnew_algo));
Core::ParseCloudPasswordAlgo(result.vnew_algo()));
settings.newSecureAlgo = Core::ValidateNewSecureSecretAlgo(
Core::ParseSecureSecretAlgo(result.vnew_secure_algo));
openssl::AddRandomSeed(bytes::make_span(result.vsecure_random.v));
Core::ParseSecureSecretAlgo(result.vnew_secure_algo()));
openssl::AddRandomSeed(bytes::make_span(result.vsecure_random().v));
return applyPassword(std::move(settings));
}