Moved App::formatPhone to td_ui.

This commit is contained in:
23rd 2021-07-26 09:32:16 +03:00
parent a14f2144e1
commit 024bb5e54f
22 changed files with 81 additions and 70 deletions

View file

@ -41,7 +41,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_controller.h" #include "window/window_controller.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "apiwrap.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 Api {
namespace { namespace {
@ -1844,7 +1845,7 @@ void Updates::feedUpdate(const MTPUpdate &update) {
|| user->isSelf() || user->isSelf()
|| user->phone().isEmpty()) || user->phone().isEmpty())
? QString() ? QString()
: App::formatPhone(user->phone())), : Ui::FormatPhone(user->phone())),
user->username); user->username);
session().changes().peerUpdated( session().changes().peerUpdated(

View file

@ -38,7 +38,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mainwindow.h" #include "mainwindow.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "numbers.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
#include "styles/style_overview.h" #include "styles/style_overview.h"
@ -70,32 +69,6 @@ HistoryView::Element *hoveredItem = nullptr,
namespace App { 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<int> 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() { void initMedia() {
Ui::StartCachedCorners(); Ui::StartCachedCorners();
} }

View file

@ -14,8 +14,6 @@ class Element;
} // namespace HistoryView } // namespace HistoryView
namespace App { namespace App {
QString formatPhone(QString phone);
void hoveredItem(HistoryView::Element *item); void hoveredItem(HistoryView::Element *item);
HistoryView::Element *hoveredItem(); HistoryView::Element *hoveredItem();
void pressedItem(HistoryView::Element *item); void pressedItem(HistoryView::Element *item);

View file

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
#include "ui/wrap/fade_wrap.h" #include "ui/wrap/fade_wrap.h"
#include "ui/toast/toast.h" #include "ui/toast/toast.h"
#include "ui/text/format_values.h" // Ui::FormatPhone
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/special_fields.h" #include "ui/special_fields.h"
#include "boxes/confirm_phone_box.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 "data/data_user.h"
#include "mtproto/sender.h" #include "mtproto/sender.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "app.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
#include "styles/style_boxes.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::lng_change_phone_occupied(
tr::now, tr::now,
lt_phone, lt_phone,
App::formatPhone(phoneNumber)), Ui::FormatPhone(phoneNumber)),
tr::lng_box_ok(tr::now))); tr::lng_box_ok(tr::now)));
} else { } else {
showError(Lang::Hard::ServerError()); showError(Lang::Hard::ServerError());
@ -271,7 +271,7 @@ void ChangePhoneBox::EnterCode::prepare() {
auto descriptionText = tr::lng_change_phone_code_description( auto descriptionText = tr::lng_change_phone_code_description(
tr::now, tr::now,
lt_phone, lt_phone,
Ui::Text::Bold(App::formatPhone(_phone)), Ui::Text::Bold(Ui::FormatPhone(_phone)),
Ui::Text::WithEntities); Ui::Text::WithEntities);
auto description = object_ptr<Ui::FlatLabel>(this, rpl::single(descriptionText), st::changePhoneLabel); auto description = object_ptr<Ui::FlatLabel>(this, rpl::single(descriptionText), st::changePhoneLabel);
description->moveToLeft(st::boxPadding.left(), 0); description->moveToLeft(st::boxPadding.left(), 0);

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
#include "ui/text/format_values.h" // Ui::FormatPhone
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "core/click_handler_types.h" // UrlClickHandler #include "core/click_handler_types.h" // UrlClickHandler
#include "base/qthelp_url.h" // qthelp::url_encode #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 "main/main_session.h"
#include "mainwidget.h" #include "mainwidget.h"
#include "numbers.h" #include "numbers.h"
#include "app.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "mtproto/facade.h" #include "mtproto/facade.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
@ -296,7 +296,7 @@ void ConfirmPhoneBox::prepare() {
this, this,
tr::lng_confirm_phone_about( tr::lng_confirm_phone_about(
lt_phone, lt_phone,
rpl::single(Ui::Text::Bold(App::formatPhone(_phone))), rpl::single(Ui::Text::Bold(Ui::FormatPhone(_phone))),
Ui::Text::WithEntities), Ui::Text::WithEntities),
st::confirmPhoneAboutLabel); st::confirmPhoneAboutLabel);
@ -347,7 +347,7 @@ void ConfirmPhoneBox::sendCode() {
void ConfirmPhoneBox::confirmDone(const MTPBool &result) { void ConfirmPhoneBox::confirmDone(const MTPBool &result) {
_sendCodeRequestId = 0; _sendCodeRequestId = 0;
Ui::show(Box<InformBox>(tr::lng_confirm_phone_success(tr::now, lt_phone, App::formatPhone(_phone)))); Ui::show(Box<InformBox>(tr::lng_confirm_phone_success(tr::now, lt_phone, Ui::FormatPhone(_phone))));
} }
void ConfirmPhoneBox::confirmFail(const MTP::Error &error) { void ConfirmPhoneBox::confirmFail(const MTP::Error &error) {

View file

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/wrap/vertical_layout.h" #include "ui/wrap/vertical_layout.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
#include "ui/widgets/input_fields.h" #include "ui/widgets/input_fields.h"
#include "ui/text/format_values.h" // Ui::FormatPhone
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "info/profile/info_profile_cover.h" #include "info/profile/info_profile_cover.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
@ -19,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/toast/toast.h" #include "ui/toast/toast.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "apiwrap.h" #include "apiwrap.h"
#include "app.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
#include "styles/style_info.h" #include "styles/style_info.h"
@ -145,7 +145,7 @@ void Controller::setupCover() {
_window, _window,
(_phone.isEmpty() (_phone.isEmpty()
? tr::lng_contact_mobile_hidden() ? tr::lng_contact_mobile_hidden()
: rpl::single(App::formatPhone(_phone)))), : rpl::single(Ui::FormatPhone(_phone)))),
style::margins())->setAttribute(Qt::WA_TransparentForMouseEvents); style::margins())->setAttribute(Qt::WA_TransparentForMouseEvents);
} }

View file

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/crash_reports.h" // CrashReports::SetAnnotation #include "core/crash_reports.h" // CrashReports::SetAnnotation
#include "ui/image/image.h" #include "ui/image/image.h"
#include "ui/image/image_location_factory.h" // Images::FromPhotoSize #include "ui/image/image_location_factory.h" // Images::FromPhotoSize
#include "ui/text/format_values.h" // Ui::FormatPhone
#include "export/export_manager.h" #include "export/export_manager.h"
#include "export/view/export_view_panel_controller.h" #include "export/view/export_view_panel_controller.h"
#include "mtproto/mtproto_config.h" #include "mtproto/mtproto_config.h"
@ -506,7 +507,7 @@ not_null<UserData*> Session::processUser(const MTPUser &data) {
const auto pname = (showPhoneChanged || phoneChanged || nameChanged) const auto pname = (showPhoneChanged || phoneChanged || nameChanged)
? ((showPhone && !phone.isEmpty()) ? ((showPhone && !phone.isEmpty())
? App::formatPhone(phone) ? Ui::FormatPhone(phone)
: QString()) : QString())
: result->nameOrPhone; : result->nameOrPhone;
@ -3587,7 +3588,7 @@ QString Session::findContactPhone(not_null<UserData*> contact) const {
const auto result = contact->phone(); const auto result = contact->phone();
return result.isEmpty() return result.isEmpty()
? findContactPhone(peerToUser(contact->id)) ? findContactPhone(peerToUser(contact->id))
: App::formatPhone(result); : Ui::FormatPhone(result);
} }
QString Session::findContactPhone(UserId contactId) const { QString Session::findContactPhone(UserId contactId) const {

View file

@ -21,10 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <range/v3/view/transform.hpp> #include <range/v3/view/transform.hpp>
#include <range/v3/range/conversion.hpp> #include <range/v3/range/conversion.hpp>
namespace App { // Hackish..
QString formatPhone(QString phone);
} // namespace App
namespace Export { namespace Export {
namespace Data { namespace Data {
namespace { namespace {
@ -1795,7 +1791,7 @@ bool SkipMessageByDate(const Message &message, const Settings &settings) {
Utf8String FormatPhoneNumber(const Utf8String &phoneNumber) { Utf8String FormatPhoneNumber(const Utf8String &phoneNumber) {
return phoneNumber.isEmpty() return phoneNumber.isEmpty()
? Utf8String() ? Utf8String()
: App::formatPhone(QString::fromUtf8(phoneNumber)).toUtf8(); : Ui::FormatPhone(QString::fromUtf8(phoneNumber)).toUtf8();
} }
Utf8String FormatDateTime( Utf8String FormatDateTime(

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
#include "ui/layers/generic_box.h" #include "ui/layers/generic_box.h"
#include "ui/toast/toast.h" #include "ui/toast/toast.h"
#include "ui/text/format_values.h" // Ui::FormatPhone
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "data/data_peer.h" #include "data/data_peer.h"
#include "data/data_user.h" #include "data/data_user.h"
@ -26,7 +27,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "main/main_session.h" #include "main/main_session.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "boxes/peers/edit_contact_box.h" #include "boxes/peers/edit_contact_box.h"
#include "app.h"
#include "styles/style_chat.h" #include "styles/style_chat.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
@ -345,7 +345,7 @@ void ContactStatus::setupShareHandler(not_null<UserData*> user) {
tr::now, tr::now,
lt_phone, lt_phone,
Ui::Text::WithEntities( Ui::Text::WithEntities(
App::formatPhone(user->session().user()->phone())), Ui::FormatPhone(user->session().user()->phone())),
lt_user, lt_user,
Ui::Text::Bold(user->name), Ui::Text::Bold(user->name),
Ui::Text::WithEntities), Ui::Text::WithEntities),

View file

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_cursor_state.h" #include "history/view/history_view_cursor_state.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "ui/empty_userpic.h" #include "ui/empty_userpic.h"
#include "ui/text/format_values.h" // Ui::FormatPhone
#include "ui/text/text_options.h" #include "ui/text/text_options.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "data/data_user.h" #include "data/data_user.h"
@ -68,7 +69,7 @@ Contact::Contact(
, _userId(userId) , _userId(userId)
, _fname(first) , _fname(first)
, _lname(last) , _lname(last)
, _phone(App::formatPhone(phone)) { , _phone(Ui::FormatPhone(phone)) {
history()->owner().registerContactView(userId, parent); history()->owner().registerContactView(userId, parent);
_name.setText( _name.setText(

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/click_handler_types.h" #include "core/click_handler_types.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "ui/wrap/slide_wrap.h" #include "ui/wrap/slide_wrap.h"
#include "ui/text/format_values.h" // Ui::FormatPhone
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "data/data_peer_values.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_user.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "boxes/peers/edit_peer_permissions_box.h" #include "boxes/peers/edit_peer_permissions_box.h"
#include "app.h"
namespace Info { namespace Info {
namespace Profile { namespace Profile {
@ -82,7 +82,7 @@ rpl::producer<TextWithEntities> PhoneValue(not_null<UserData*> user) {
user, user,
UpdateFlag::PhoneNumber UpdateFlag::PhoneNumber
) | rpl::map([=] { ) | rpl::map([=] {
return App::formatPhone(user->phone()); return Ui::FormatPhone(user->phone());
}) | Ui::Text::ToWithEntities(); }) | Ui::Text::ToWithEntities();
} }

View file

@ -15,7 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/history_message.h" #include "history/history_message.h"
#include "data/data_channel.h" #include "data/data_channel.h"
#include "app.h" #include "ui/text/format_values.h" // Ui::FormatPhone
namespace InlineBots { namespace InlineBots {
namespace internal { namespace internal {
@ -141,7 +141,7 @@ SendDataCommon::SentMTPMessageFields SendContact::getSentMessageFields() const {
QString SendContact::getLayoutDescription(const Result *owner) const { QString SendContact::getLayoutDescription(const Result *owner) const {
auto result = SendData::getLayoutDescription(owner); auto result = SendData::getLayoutDescription(owner);
if (result.isEmpty()) { if (result.isEmpty()) {
return App::formatPhone(_phoneNumber); return Ui::FormatPhone(_phoneNumber);
} }
return result; return result;
} }

View file

@ -13,11 +13,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/update_checker.h" #include "core/update_checker.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
#include "ui/text/format_values.h" // Ui::FormatPhone
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "main/main_account.h" #include "main/main_account.h"
#include "mtproto/mtp_instance.h" #include "mtproto/mtp_instance.h"
#include "app.h"
#include "styles/style_intro.h" #include "styles/style_intro.h"
namespace Intro { namespace Intro {
@ -99,7 +99,7 @@ CodeWidget::CodeWidget(
_code->setDigitsCountMax(getData()->codeLength); _code->setDigitsCountMax(getData()->codeLength);
setTitleText(rpl::single(App::formatPhone(getData()->phone))); setTitleText(rpl::single(Ui::FormatPhone(getData()->phone)));
updateDescText(); updateDescText();
} }

View file

@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_countries.h" #include "data/data_countries.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "ui/text/format_values.h" // Ui::FormatPhone
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/widgets/buttons.h" #include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h" #include "ui/widgets/labels.h"
@ -551,7 +552,7 @@ void Widget::resetAccount() {
Ui::show(Box<InformBox>(tr::lng_signin_reset_wait( Ui::show(Box<InformBox>(tr::lng_signin_reset_wait(
tr::now, tr::now,
lt_phone_number, lt_phone_number,
App::formatPhone(getData()->phone), Ui::FormatPhone(getData()->phone),
lt_when, lt_when,
when))); when)));
} else if (type == qstr("2FA_RECENT_CONFIRM")) { } else if (type == qstr("2FA_RECENT_CONFIRM")) {

View file

@ -24,7 +24,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/format_values.h" #include "ui/text/format_values.h"
#include "core/update_checker.h" #include "core/update_checker.h"
#include "data/data_countries.h" #include "data/data_countries.h"
#include "app.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
namespace Passport { namespace Passport {
@ -485,7 +484,7 @@ EditContactScheme GetContactScheme(Scope::Type type) {
).match(value).hasMatch(); ).match(value).hasMatch();
}; };
result.format = [](const QString &value) { result.format = [](const QString &value) {
return App::formatPhone(value); return Ui::FormatPhone(value);
}; };
result.postprocess = [](QString value) { result.postprocess = [](QString value) {
return value.replace(QRegularExpression("[^\\d]"), QString()); return value.replace(QRegularExpression("[^\\d]"), QString());

View file

@ -17,6 +17,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/wrap/vertical_layout.h" #include "ui/wrap/vertical_layout.h"
#include "ui/wrap/slide_wrap.h" #include "ui/wrap/slide_wrap.h"
#include "ui/wrap/fade_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/text/text_utilities.h" // Ui::Text::ToUpper
#include "ui/special_fields.h" #include "ui/special_fields.h"
#include "boxes/abstract_box.h" #include "boxes/abstract_box.h"
@ -24,7 +25,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h" #include "data/data_user.h"
#include "main/main_session.h" #include "main/main_session.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "app.h"
#include "styles/style_passport.h" #include "styles/style_passport.h"
#include "styles/style_layers.h" #include "styles/style_layers.h"
@ -401,7 +401,7 @@ object_ptr<Ui::BoxContent> VerifyPhoneBox(
tr::lng_passport_confirm_phone( tr::lng_passport_confirm_phone(
tr::now, tr::now,
lt_phone, lt_phone,
App::formatPhone(phone)), Ui::FormatPhone(phone)),
codeLength, codeLength,
submit, submit,
nullptr, nullptr,

View file

@ -22,10 +22,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_payments.h" #include "styles/style_payments.h"
#include "styles/style_passport.h" #include "styles/style_passport.h"
namespace App {
QString formatPhone(QString phone); // #TODO
} // namespace App
namespace Payments::Ui { namespace Payments::Ui {
namespace { namespace {
@ -551,7 +547,7 @@ void FormSummary::setupSections(not_null<VerticalLayout*> layout) {
tr::lng_payments_info_phone(), tr::lng_payments_info_phone(),
(_information.phone.isEmpty() (_information.phone.isEmpty()
? QString() ? QString()
: App::formatPhone(_information.phone)), : Ui::FormatPhone(_information.phone)),
&st::paymentsIconPhone, &st::paymentsIconPhone,
[=] { _delegate->panelEditPhone(); }); [=] { _delegate->panelEditPhone(); });
} }

View file

@ -31,13 +31,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/wrap/slide_wrap.h" #include "ui/wrap/slide_wrap.h"
#include "ui/image/image_prepare.h" #include "ui/image/image_prepare.h"
#include "ui/cached_round_corners.h" #include "ui/cached_round_corners.h"
#include "ui/text/format_values.h" // Ui::FormatPhone
#include "window/section_widget.h" #include "window/section_widget.h"
#include "window/window_session_controller.h" #include "window/window_session_controller.h"
#include "boxes/peer_list_controllers.h" #include "boxes/peer_list_controllers.h"
#include "boxes/confirm_box.h" #include "boxes/confirm_box.h"
#include "settings/settings_privacy_security.h" #include "settings/settings_privacy_security.h"
#include "facades.h" #include "facades.h"
#include "app.h"
#include "styles/style_chat.h" #include "styles/style_chat.h"
#include "styles/style_boxes.h" #include "styles/style_boxes.h"
#include "styles/style_settings.h" #include "styles/style_settings.h"
@ -330,7 +330,7 @@ std::unique_ptr<PeerListRow> BlockedBoxController::createRow(
if (!user) { if (!user) {
return tr::lng_group_status(tr::now); return tr::lng_group_status(tr::now);
} else if (!user->phone().isEmpty()) { } else if (!user->phone().isEmpty()) {
return App::formatPhone(user->phone()); return Ui::FormatPhone(user->phone());
} else if (!user->username.isEmpty()) { } else if (!user->username.isEmpty()) {
return '@' + user->username; return '@' + user->username;
} else if (user->isBot()) { } else if (user->isBot()) {

View file

@ -14,7 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_user.h" #include "data/data_user.h"
#include "data/data_session.h" #include "data/data_session.h"
#include "ui/image/image.h" #include "ui/image/image.h"
#include "app.h" #include "ui/text/format_values.h" // Ui::FormatPhone
namespace Serialize { namespace Serialize {
namespace { namespace {
@ -231,7 +231,7 @@ PeerData *readPeer(
&& (user->id != selfId) && (user->id != selfId)
&& (contact <= 0); && (contact <= 0);
const auto pname = (showPhone && !phone.isEmpty()) const auto pname = (showPhone && !phone.isEmpty())
? App::formatPhone(phone) ? Ui::FormatPhone(phone)
: QString(); : QString();
user->setPhone(phone); user->setPhone(phone);

View file

@ -8,7 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/format_values.h" #include "ui/text/format_values.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "numbers.h" // phoneNumberParse
#include <QRegularExpression>
#include <QtCore/QLocale> #include <QtCore/QLocale>
#include <locale> #include <locale>
#include <sstream> #include <sstream>
@ -369,4 +371,45 @@ QString FormatImageSizeText(const QSize &size) {
+ QString::number(size.height()); + 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 } // namespace Ui

View file

@ -23,6 +23,7 @@ inline constexpr auto FileStatusSizeFailed = 0x7FFFFFF2;
[[nodiscard]] QString FormatGifAndSizeText(qint64 size); [[nodiscard]] QString FormatGifAndSizeText(qint64 size);
[[nodiscard]] QString FormatPlayedText(qint64 played, qint64 duration); [[nodiscard]] QString FormatPlayedText(qint64 played, qint64 duration);
[[nodiscard]] QString FormatImageSizeText(const QSize &size); [[nodiscard]] QString FormatImageSizeText(const QSize &size);
[[nodiscard]] QString FormatPhone(QString phone);
struct CurrencyRule { struct CurrencyRule {
const char *international = ""; const char *international = "";

View file

@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/shadow.h" #include "ui/widgets/shadow.h"
#include "ui/wrap/slide_wrap.h" #include "ui/wrap/slide_wrap.h"
#include "ui/wrap/vertical_layout.h" #include "ui/wrap/vertical_layout.h"
#include "ui/text/format_values.h" // Ui::FormatPhone
#include "ui/text/text_utilities.h" #include "ui/text/text_utilities.h"
#include "ui/special_buttons.h" #include "ui/special_buttons.h"
#include "ui/empty_userpic.h" #include "ui/empty_userpic.h"
@ -1084,7 +1085,7 @@ void MainMenu::updateInnerControlsGeometry() {
} }
void MainMenu::updatePhone() { void MainMenu::updatePhone() {
_phoneText = App::formatPhone(_controller->session().user()->phone()); _phoneText = Ui::FormatPhone(_controller->session().user()->phone());
update(); update();
} }