From aec4857e7b6dc70765e91f74d3724bd77c2d7297 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 1 Mar 2024 03:50:11 +0300 Subject: [PATCH] Fixed format of phone number in intro widget. --- Telegram/SourceFiles/intro/intro_phone.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/intro/intro_phone.cpp b/Telegram/SourceFiles/intro/intro_phone.cpp index 7ac420956..5e8261674 100644 --- a/Telegram/SourceFiles/intro/intro_phone.cpp +++ b/Telegram/SourceFiles/intro/intro_phone.cpp @@ -32,13 +32,18 @@ namespace Intro { namespace details { namespace { -bool AllowPhoneAttempt(const QString &phone) { +[[nodiscard]] bool AllowPhoneAttempt(const QString &phone) { const auto digits = ranges::count_if( phone, [](QChar ch) { return ch.isNumber(); }); return (digits > 1); } +[[nodiscard]] QString DigitsOnly(QString value) { + static const auto RegExp = QRegularExpression("[^0-9]"); + return value.replace(RegExp, QString()); +} + } // namespace PhoneWidget::PhoneWidget( @@ -168,16 +173,12 @@ void PhoneWidget::submit() { cancelNearestDcRequest(); // Check if such account is authorized already. - const auto digitsOnly = [](QString value) { - static const auto RegExp = QRegularExpression("[^0-9]"); - return value.replace(RegExp, QString()); - }; - const auto phoneDigits = digitsOnly(phone); + const auto phoneDigits = DigitsOnly(phone); for (const auto &[index, existing] : Core::App().domain().accounts()) { const auto raw = existing.get(); if (const auto session = raw->maybeSession()) { if (raw->mtp().environment() == account().mtp().environment() - && digitsOnly(session->user()->phone()) == phoneDigits) { + && DigitsOnly(session->user()->phone()) == phoneDigits) { crl::on_main(raw, [=] { Core::App().domain().activate(raw); }); @@ -231,7 +232,7 @@ void PhoneWidget::phoneSubmitDone(const MTPauth_SentCode &result) { result.match([&](const MTPDauth_sentCode &data) { fillSentCodeData(data); - getData()->phone = _sentPhone; + getData()->phone = DigitsOnly(_sentPhone); getData()->phoneHash = qba(data.vphone_code_hash()); const auto next = data.vnext_type(); if (next && next->type() == mtpc_auth_codeTypeCall) {