Fixed format of phone number in intro widget.

This commit is contained in:
23rd 2024-03-01 03:50:11 +03:00 committed by John Preston
parent 5dc6bdcc42
commit aec4857e7b

View file

@ -32,13 +32,18 @@ namespace Intro {
namespace details { namespace details {
namespace { namespace {
bool AllowPhoneAttempt(const QString &phone) { [[nodiscard]] bool AllowPhoneAttempt(const QString &phone) {
const auto digits = ranges::count_if( const auto digits = ranges::count_if(
phone, phone,
[](QChar ch) { return ch.isNumber(); }); [](QChar ch) { return ch.isNumber(); });
return (digits > 1); return (digits > 1);
} }
[[nodiscard]] QString DigitsOnly(QString value) {
static const auto RegExp = QRegularExpression("[^0-9]");
return value.replace(RegExp, QString());
}
} // namespace } // namespace
PhoneWidget::PhoneWidget( PhoneWidget::PhoneWidget(
@ -168,16 +173,12 @@ void PhoneWidget::submit() {
cancelNearestDcRequest(); cancelNearestDcRequest();
// Check if such account is authorized already. // Check if such account is authorized already.
const auto digitsOnly = [](QString value) { const auto phoneDigits = DigitsOnly(phone);
static const auto RegExp = QRegularExpression("[^0-9]");
return value.replace(RegExp, QString());
};
const auto phoneDigits = digitsOnly(phone);
for (const auto &[index, existing] : Core::App().domain().accounts()) { for (const auto &[index, existing] : Core::App().domain().accounts()) {
const auto raw = existing.get(); const auto raw = existing.get();
if (const auto session = raw->maybeSession()) { if (const auto session = raw->maybeSession()) {
if (raw->mtp().environment() == account().mtp().environment() if (raw->mtp().environment() == account().mtp().environment()
&& digitsOnly(session->user()->phone()) == phoneDigits) { && DigitsOnly(session->user()->phone()) == phoneDigits) {
crl::on_main(raw, [=] { crl::on_main(raw, [=] {
Core::App().domain().activate(raw); Core::App().domain().activate(raw);
}); });
@ -231,7 +232,7 @@ void PhoneWidget::phoneSubmitDone(const MTPauth_SentCode &result) {
result.match([&](const MTPDauth_sentCode &data) { result.match([&](const MTPDauth_sentCode &data) {
fillSentCodeData(data); fillSentCodeData(data);
getData()->phone = _sentPhone; getData()->phone = DigitsOnly(_sentPhone);
getData()->phoneHash = qba(data.vphone_code_hash()); getData()->phoneHash = qba(data.vphone_code_hash());
const auto next = data.vnext_type(); const auto next = data.vnext_type();
if (next && next->type() == mtpc_auth_codeTypeCall) { if (next && next->type() == mtpc_auth_codeTypeCall) {