From 024bb5e54fcb33bc624ceaec9dde8df8b05c7822 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 26 Jul 2021 09:32:16 +0300 Subject: [PATCH] Moved App::formatPhone to td_ui. --- Telegram/SourceFiles/api/api_updates.cpp | 5 ++- Telegram/SourceFiles/app.cpp | 27 ------------ Telegram/SourceFiles/app.h | 2 - .../SourceFiles/boxes/change_phone_box.cpp | 6 +-- .../SourceFiles/boxes/confirm_phone_box.cpp | 6 +-- .../boxes/peers/edit_contact_box.cpp | 4 +- Telegram/SourceFiles/data/data_session.cpp | 5 ++- .../export/data/export_data_types.cpp | 6 +-- .../view/history_view_contact_status.cpp | 4 +- .../view/media/history_view_contact.cpp | 3 +- .../info/profile/info_profile_values.cpp | 4 +- .../inline_bots/inline_bot_send_data.cpp | 4 +- Telegram/SourceFiles/intro/intro_code.cpp | 4 +- Telegram/SourceFiles/intro/intro_widget.cpp | 3 +- .../passport/passport_panel_controller.cpp | 3 +- .../passport/passport_panel_edit_contact.cpp | 4 +- .../payments/ui/payments_form_summary.cpp | 6 +-- .../settings/settings_privacy_controllers.cpp | 4 +- .../SourceFiles/storage/serialize_peer.cpp | 4 +- .../SourceFiles/ui/text/format_values.cpp | 43 +++++++++++++++++++ Telegram/SourceFiles/ui/text/format_values.h | 1 + .../SourceFiles/window/window_main_menu.cpp | 3 +- 22 files changed, 81 insertions(+), 70 deletions(-) diff --git a/Telegram/SourceFiles/api/api_updates.cpp b/Telegram/SourceFiles/api/api_updates.cpp index 314f65298..6d80063b6 100644 --- a/Telegram/SourceFiles/api/api_updates.cpp +++ b/Telegram/SourceFiles/api/api_updates.cpp @@ -41,7 +41,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "window/window_controller.h" #include "boxes/confirm_box.h" #include "apiwrap.h" -#include "app.h" // App::formatPhone +#include "ui/text/format_values.h" // Ui::FormatPhone +#include "app.h" // App::quitting namespace Api { namespace { @@ -1844,7 +1845,7 @@ void Updates::feedUpdate(const MTPUpdate &update) { || user->isSelf() || user->phone().isEmpty()) ? QString() - : App::formatPhone(user->phone())), + : Ui::FormatPhone(user->phone())), user->username); session().changes().peerUpdated( diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index 70c0fc178..ee0ef90cb 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -38,7 +38,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwindow.h" #include "mainwidget.h" #include "apiwrap.h" -#include "numbers.h" #include "main/main_session.h" #include "styles/style_boxes.h" #include "styles/style_overview.h" @@ -70,32 +69,6 @@ HistoryView::Element *hoveredItem = nullptr, namespace App { - QString formatPhone(QString phone) { - if (phone.isEmpty()) return QString(); - if (phone.at(0) == '0') return phone; - - QString number = phone; - for (const QChar *ch = phone.constData(), *e = ch + phone.size(); ch != e; ++ch) { - if (ch->unicode() < '0' || ch->unicode() > '9') { - number = phone.replace(QRegularExpression(qsl("[^\\d]")), QString()); - } - } - QVector groups = phoneNumberParse(number); - if (groups.isEmpty()) return '+' + number; - - QString result; - result.reserve(number.size() + groups.size() + 1); - result.append('+'); - int32 sum = 0; - for (int32 i = 0, l = groups.size(); i < l; ++i) { - result.append(number.midRef(sum, groups.at(i))); - sum += groups.at(i); - if (sum < number.size()) result.append(' '); - } - if (sum < number.size()) result.append(number.midRef(sum)); - return result; - } - void initMedia() { Ui::StartCachedCorners(); } diff --git a/Telegram/SourceFiles/app.h b/Telegram/SourceFiles/app.h index 9b82f25aa..6e581251b 100644 --- a/Telegram/SourceFiles/app.h +++ b/Telegram/SourceFiles/app.h @@ -14,8 +14,6 @@ class Element; } // namespace HistoryView namespace App { - QString formatPhone(QString phone); - void hoveredItem(HistoryView::Element *item); HistoryView::Element *hoveredItem(); void pressedItem(HistoryView::Element *item); diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index 199ebeab5..5de47051d 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/input_fields.h" #include "ui/wrap/fade_wrap.h" #include "ui/toast/toast.h" +#include "ui/text/format_values.h" // Ui::FormatPhone #include "ui/text/text_utilities.h" #include "ui/special_fields.h" #include "boxes/confirm_phone_box.h" @@ -21,7 +22,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "mtproto/sender.h" #include "apiwrap.h" -#include "app.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" @@ -235,7 +235,7 @@ void ChangePhoneBox::EnterPhone::sendPhoneFail(const MTP::Error &error, const QS tr::lng_change_phone_occupied( tr::now, lt_phone, - App::formatPhone(phoneNumber)), + Ui::FormatPhone(phoneNumber)), tr::lng_box_ok(tr::now))); } else { showError(Lang::Hard::ServerError()); @@ -271,7 +271,7 @@ void ChangePhoneBox::EnterCode::prepare() { auto descriptionText = tr::lng_change_phone_code_description( tr::now, lt_phone, - Ui::Text::Bold(App::formatPhone(_phone)), + Ui::Text::Bold(Ui::FormatPhone(_phone)), Ui::Text::WithEntities); auto description = object_ptr(this, rpl::single(descriptionText), st::changePhoneLabel); description->moveToLeft(st::boxPadding.left(), 0); diff --git a/Telegram/SourceFiles/boxes/confirm_phone_box.cpp b/Telegram/SourceFiles/boxes/confirm_phone_box.cpp index 3d960f668..51ac3a919 100644 --- a/Telegram/SourceFiles/boxes/confirm_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_phone_box.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/input_fields.h" #include "ui/widgets/labels.h" +#include "ui/text/format_values.h" // Ui::FormatPhone #include "ui/text/text_utilities.h" #include "core/click_handler_types.h" // UrlClickHandler #include "base/qthelp_url.h" // qthelp::url_encode @@ -18,7 +19,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "mainwidget.h" #include "numbers.h" -#include "app.h" #include "lang/lang_keys.h" #include "mtproto/facade.h" #include "styles/style_layers.h" @@ -296,7 +296,7 @@ void ConfirmPhoneBox::prepare() { this, tr::lng_confirm_phone_about( lt_phone, - rpl::single(Ui::Text::Bold(App::formatPhone(_phone))), + rpl::single(Ui::Text::Bold(Ui::FormatPhone(_phone))), Ui::Text::WithEntities), st::confirmPhoneAboutLabel); @@ -347,7 +347,7 @@ void ConfirmPhoneBox::sendCode() { void ConfirmPhoneBox::confirmDone(const MTPBool &result) { _sendCodeRequestId = 0; - Ui::show(Box(tr::lng_confirm_phone_success(tr::now, lt_phone, App::formatPhone(_phone)))); + Ui::show(Box(tr::lng_confirm_phone_success(tr::now, lt_phone, Ui::FormatPhone(_phone)))); } void ConfirmPhoneBox::confirmFail(const MTP::Error &error) { diff --git a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp index 26feabcb1..42feaef29 100644 --- a/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp +++ b/Telegram/SourceFiles/boxes/peers/edit_contact_box.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/vertical_layout.h" #include "ui/widgets/labels.h" #include "ui/widgets/input_fields.h" +#include "ui/text/format_values.h" // Ui::FormatPhone #include "ui/text/text_utilities.h" #include "info/profile/info_profile_cover.h" #include "lang/lang_keys.h" @@ -19,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/toast/toast.h" #include "main/main_session.h" #include "apiwrap.h" -#include "app.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" #include "styles/style_info.h" @@ -145,7 +145,7 @@ void Controller::setupCover() { _window, (_phone.isEmpty() ? tr::lng_contact_mobile_hidden() - : rpl::single(App::formatPhone(_phone)))), + : rpl::single(Ui::FormatPhone(_phone)))), style::margins())->setAttribute(Qt::WA_TransparentForMouseEvents); } diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index d2f82e73a..3887779a9 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/crash_reports.h" // CrashReports::SetAnnotation #include "ui/image/image.h" #include "ui/image/image_location_factory.h" // Images::FromPhotoSize +#include "ui/text/format_values.h" // Ui::FormatPhone #include "export/export_manager.h" #include "export/view/export_view_panel_controller.h" #include "mtproto/mtproto_config.h" @@ -506,7 +507,7 @@ not_null Session::processUser(const MTPUser &data) { const auto pname = (showPhoneChanged || phoneChanged || nameChanged) ? ((showPhone && !phone.isEmpty()) - ? App::formatPhone(phone) + ? Ui::FormatPhone(phone) : QString()) : result->nameOrPhone; @@ -3587,7 +3588,7 @@ QString Session::findContactPhone(not_null contact) const { const auto result = contact->phone(); return result.isEmpty() ? findContactPhone(peerToUser(contact->id)) - : App::formatPhone(result); + : Ui::FormatPhone(result); } QString Session::findContactPhone(UserId contactId) const { diff --git a/Telegram/SourceFiles/export/data/export_data_types.cpp b/Telegram/SourceFiles/export/data/export_data_types.cpp index b2f45cf7c..421b02d67 100644 --- a/Telegram/SourceFiles/export/data/export_data_types.cpp +++ b/Telegram/SourceFiles/export/data/export_data_types.cpp @@ -21,10 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include -namespace App { // Hackish.. -QString formatPhone(QString phone); -} // namespace App - namespace Export { namespace Data { namespace { @@ -1795,7 +1791,7 @@ bool SkipMessageByDate(const Message &message, const Settings &settings) { Utf8String FormatPhoneNumber(const Utf8String &phoneNumber) { return phoneNumber.isEmpty() ? Utf8String() - : App::formatPhone(QString::fromUtf8(phoneNumber)).toUtf8(); + : Ui::FormatPhone(QString::fromUtf8(phoneNumber)).toUtf8(); } Utf8String FormatDateTime( diff --git a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp index a259a9a59..ee9c02df6 100644 --- a/Telegram/SourceFiles/history/view/history_view_contact_status.cpp +++ b/Telegram/SourceFiles/history/view/history_view_contact_status.cpp @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/labels.h" #include "ui/layers/generic_box.h" #include "ui/toast/toast.h" +#include "ui/text/format_values.h" // Ui::FormatPhone #include "ui/text/text_utilities.h" #include "data/data_peer.h" #include "data/data_user.h" @@ -26,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "boxes/confirm_box.h" #include "boxes/peers/edit_contact_box.h" -#include "app.h" #include "styles/style_chat.h" #include "styles/style_layers.h" @@ -345,7 +345,7 @@ void ContactStatus::setupShareHandler(not_null user) { tr::now, lt_phone, Ui::Text::WithEntities( - App::formatPhone(user->session().user()->phone())), + Ui::FormatPhone(user->session().user()->phone())), lt_user, Ui::Text::Bold(user->name), Ui::Text::WithEntities), diff --git a/Telegram/SourceFiles/history/view/media/history_view_contact.cpp b/Telegram/SourceFiles/history/view/media/history_view_contact.cpp index 881702af8..b7f1fc163 100644 --- a/Telegram/SourceFiles/history/view/media/history_view_contact.cpp +++ b/Telegram/SourceFiles/history/view/media/history_view_contact.cpp @@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/view/history_view_cursor_state.h" #include "window/window_session_controller.h" #include "ui/empty_userpic.h" +#include "ui/text/format_values.h" // Ui::FormatPhone #include "ui/text/text_options.h" #include "data/data_session.h" #include "data/data_user.h" @@ -68,7 +69,7 @@ Contact::Contact( , _userId(userId) , _fname(first) , _lname(last) -, _phone(App::formatPhone(phone)) { +, _phone(Ui::FormatPhone(phone)) { history()->owner().registerContactView(userId, parent); _name.setText( diff --git a/Telegram/SourceFiles/info/profile/info_profile_values.cpp b/Telegram/SourceFiles/info/profile/info_profile_values.cpp index 2d076d957..773869a64 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_values.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_values.cpp @@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/click_handler_types.h" #include "main/main_session.h" #include "ui/wrap/slide_wrap.h" +#include "ui/text/format_values.h" // Ui::FormatPhone #include "ui/text/text_utilities.h" #include "lang/lang_keys.h" #include "data/data_peer_values.h" @@ -22,7 +23,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_session.h" #include "boxes/peers/edit_peer_permissions_box.h" -#include "app.h" namespace Info { namespace Profile { @@ -82,7 +82,7 @@ rpl::producer PhoneValue(not_null user) { user, UpdateFlag::PhoneNumber ) | rpl::map([=] { - return App::formatPhone(user->phone()); + return Ui::FormatPhone(user->phone()); }) | Ui::Text::ToWithEntities(); } diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp index 70db1395e..3610027f3 100644 --- a/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp +++ b/Telegram/SourceFiles/inline_bots/inline_bot_send_data.cpp @@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history.h" #include "history/history_message.h" #include "data/data_channel.h" -#include "app.h" +#include "ui/text/format_values.h" // Ui::FormatPhone namespace InlineBots { namespace internal { @@ -141,7 +141,7 @@ SendDataCommon::SentMTPMessageFields SendContact::getSentMessageFields() const { QString SendContact::getLayoutDescription(const Result *owner) const { auto result = SendData::getLayoutDescription(owner); if (result.isEmpty()) { - return App::formatPhone(_phoneNumber); + return Ui::FormatPhone(_phoneNumber); } return result; } diff --git a/Telegram/SourceFiles/intro/intro_code.cpp b/Telegram/SourceFiles/intro/intro_code.cpp index b99f86d97..99073bb39 100644 --- a/Telegram/SourceFiles/intro/intro_code.cpp +++ b/Telegram/SourceFiles/intro/intro_code.cpp @@ -13,11 +13,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/update_checker.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" +#include "ui/text/format_values.h" // Ui::FormatPhone #include "ui/text/text_utilities.h" #include "boxes/confirm_box.h" #include "main/main_account.h" #include "mtproto/mtp_instance.h" -#include "app.h" #include "styles/style_intro.h" namespace Intro { @@ -99,7 +99,7 @@ CodeWidget::CodeWidget( _code->setDigitsCountMax(getData()->codeLength); - setTitleText(rpl::single(App::formatPhone(getData()->phone))); + setTitleText(rpl::single(Ui::FormatPhone(getData()->phone))); updateDescText(); } diff --git a/Telegram/SourceFiles/intro/intro_widget.cpp b/Telegram/SourceFiles/intro/intro_widget.cpp index f1e012e76..1415364b3 100644 --- a/Telegram/SourceFiles/intro/intro_widget.cpp +++ b/Telegram/SourceFiles/intro/intro_widget.cpp @@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_countries.h" #include "boxes/confirm_box.h" +#include "ui/text/format_values.h" // Ui::FormatPhone #include "ui/text/text_utilities.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" @@ -551,7 +552,7 @@ void Widget::resetAccount() { Ui::show(Box(tr::lng_signin_reset_wait( tr::now, lt_phone_number, - App::formatPhone(getData()->phone), + Ui::FormatPhone(getData()->phone), lt_when, when))); } else if (type == qstr("2FA_RECENT_CONFIRM")) { diff --git a/Telegram/SourceFiles/passport/passport_panel_controller.cpp b/Telegram/SourceFiles/passport/passport_panel_controller.cpp index 547c2ea46..05e27fdd3 100644 --- a/Telegram/SourceFiles/passport/passport_panel_controller.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_controller.cpp @@ -24,7 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/format_values.h" #include "core/update_checker.h" #include "data/data_countries.h" -#include "app.h" #include "styles/style_layers.h" namespace Passport { @@ -485,7 +484,7 @@ EditContactScheme GetContactScheme(Scope::Type type) { ).match(value).hasMatch(); }; result.format = [](const QString &value) { - return App::formatPhone(value); + return Ui::FormatPhone(value); }; result.postprocess = [](QString value) { return value.replace(QRegularExpression("[^\\d]"), QString()); diff --git a/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp b/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp index bc89da5c1..5275496d3 100644 --- a/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp +++ b/Telegram/SourceFiles/passport/passport_panel_edit_contact.cpp @@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/vertical_layout.h" #include "ui/wrap/slide_wrap.h" #include "ui/wrap/fade_wrap.h" +#include "ui/text/format_values.h" // Ui::FormatPhone #include "ui/text/text_utilities.h" // Ui::Text::ToUpper #include "ui/special_fields.h" #include "boxes/abstract_box.h" @@ -24,7 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "main/main_session.h" #include "lang/lang_keys.h" -#include "app.h" #include "styles/style_passport.h" #include "styles/style_layers.h" @@ -401,7 +401,7 @@ object_ptr VerifyPhoneBox( tr::lng_passport_confirm_phone( tr::now, lt_phone, - App::formatPhone(phone)), + Ui::FormatPhone(phone)), codeLength, submit, nullptr, diff --git a/Telegram/SourceFiles/payments/ui/payments_form_summary.cpp b/Telegram/SourceFiles/payments/ui/payments_form_summary.cpp index 40807cb0d..4aeae7d25 100644 --- a/Telegram/SourceFiles/payments/ui/payments_form_summary.cpp +++ b/Telegram/SourceFiles/payments/ui/payments_form_summary.cpp @@ -22,10 +22,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_payments.h" #include "styles/style_passport.h" -namespace App { -QString formatPhone(QString phone); // #TODO -} // namespace App - namespace Payments::Ui { namespace { @@ -551,7 +547,7 @@ void FormSummary::setupSections(not_null layout) { tr::lng_payments_info_phone(), (_information.phone.isEmpty() ? QString() - : App::formatPhone(_information.phone)), + : Ui::FormatPhone(_information.phone)), &st::paymentsIconPhone, [=] { _delegate->panelEditPhone(); }); } diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index cfa37a7b3..56678f5c8 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -31,13 +31,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/slide_wrap.h" #include "ui/image/image_prepare.h" #include "ui/cached_round_corners.h" +#include "ui/text/format_values.h" // Ui::FormatPhone #include "window/section_widget.h" #include "window/window_session_controller.h" #include "boxes/peer_list_controllers.h" #include "boxes/confirm_box.h" #include "settings/settings_privacy_security.h" #include "facades.h" -#include "app.h" #include "styles/style_chat.h" #include "styles/style_boxes.h" #include "styles/style_settings.h" @@ -330,7 +330,7 @@ std::unique_ptr BlockedBoxController::createRow( if (!user) { return tr::lng_group_status(tr::now); } else if (!user->phone().isEmpty()) { - return App::formatPhone(user->phone()); + return Ui::FormatPhone(user->phone()); } else if (!user->username.isEmpty()) { return '@' + user->username; } else if (user->isBot()) { diff --git a/Telegram/SourceFiles/storage/serialize_peer.cpp b/Telegram/SourceFiles/storage/serialize_peer.cpp index 499ca252b..c9b8c7413 100644 --- a/Telegram/SourceFiles/storage/serialize_peer.cpp +++ b/Telegram/SourceFiles/storage/serialize_peer.cpp @@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "data/data_session.h" #include "ui/image/image.h" -#include "app.h" +#include "ui/text/format_values.h" // Ui::FormatPhone namespace Serialize { namespace { @@ -231,7 +231,7 @@ PeerData *readPeer( && (user->id != selfId) && (contact <= 0); const auto pname = (showPhone && !phone.isEmpty()) - ? App::formatPhone(phone) + ? Ui::FormatPhone(phone) : QString(); user->setPhone(phone); diff --git a/Telegram/SourceFiles/ui/text/format_values.cpp b/Telegram/SourceFiles/ui/text/format_values.cpp index b44d7ebd5..9d6ea95b3 100644 --- a/Telegram/SourceFiles/ui/text/format_values.cpp +++ b/Telegram/SourceFiles/ui/text/format_values.cpp @@ -8,7 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/text/format_values.h" #include "lang/lang_keys.h" +#include "numbers.h" // phoneNumberParse +#include #include #include #include @@ -369,4 +371,45 @@ QString FormatImageSizeText(const QSize &size) { + QString::number(size.height()); } +QString FormatPhone(QString phone) { + if (phone.isEmpty()) { + return QString(); + } + if (phone.at(0) == '0') { + return phone; + } + + auto number = phone; + { + const auto *ch = phone.constData(); + const auto *e = ch + phone.size(); + const auto regExp = QRegularExpression(u"[^\\d]"_q); + for (; ch != e; ++ch) { + if (ch->unicode() < '0' || ch->unicode() > '9') { + number = phone.replace(regExp, QString()); + } + } + } + const auto groups = phoneNumberParse(number); + if (groups.isEmpty()) { + return '+' + number; + } + + QString result; + result.reserve(number.size() + groups.size() + 1); + result.append('+'); + int32 sum = 0; + for (const auto &group : groups) { + result.append(number.midRef(sum, group)); + sum += group; + if (sum < number.size()) { + result.append(' '); + } + } + if (sum < number.size()) { + result.append(number.midRef(sum)); + } + return result; +} + } // namespace Ui diff --git a/Telegram/SourceFiles/ui/text/format_values.h b/Telegram/SourceFiles/ui/text/format_values.h index 1d47f2b45..c3fc5ff69 100644 --- a/Telegram/SourceFiles/ui/text/format_values.h +++ b/Telegram/SourceFiles/ui/text/format_values.h @@ -23,6 +23,7 @@ inline constexpr auto FileStatusSizeFailed = 0x7FFFFFF2; [[nodiscard]] QString FormatGifAndSizeText(qint64 size); [[nodiscard]] QString FormatPlayedText(qint64 played, qint64 duration); [[nodiscard]] QString FormatImageSizeText(const QSize &size); +[[nodiscard]] QString FormatPhone(QString phone); struct CurrencyRule { const char *international = ""; diff --git a/Telegram/SourceFiles/window/window_main_menu.cpp b/Telegram/SourceFiles/window/window_main_menu.cpp index 3379e6589..eb7f6c0f8 100644 --- a/Telegram/SourceFiles/window/window_main_menu.cpp +++ b/Telegram/SourceFiles/window/window_main_menu.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/shadow.h" #include "ui/wrap/slide_wrap.h" #include "ui/wrap/vertical_layout.h" +#include "ui/text/format_values.h" // Ui::FormatPhone #include "ui/text/text_utilities.h" #include "ui/special_buttons.h" #include "ui/empty_userpic.h" @@ -1084,7 +1085,7 @@ void MainMenu::updateInnerControlsGeometry() { } void MainMenu::updatePhone() { - _phoneText = App::formatPhone(_controller->session().user()->phone()); + _phoneText = Ui::FormatPhone(_controller->session().user()->phone()); update(); }