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 "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(

View File

@ -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<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() {
Ui::StartCachedCorners();
}

View File

@ -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);

View File

@ -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<Ui::FlatLabel>(this, rpl::single(descriptionText), st::changePhoneLabel);
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/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<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) {

View File

@ -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);
}

View File

@ -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<UserData*> 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<UserData*> 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 {

View File

@ -21,10 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <range/v3/view/transform.hpp>
#include <range/v3/range/conversion.hpp>
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(

View File

@ -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<UserData*> 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),

View File

@ -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(

View File

@ -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<TextWithEntities> PhoneValue(not_null<UserData*> user) {
user,
UpdateFlag::PhoneNumber
) | rpl::map([=] {
return App::formatPhone(user->phone());
return Ui::FormatPhone(user->phone());
}) | Ui::Text::ToWithEntities();
}

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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<InformBox>(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")) {

View File

@ -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());

View File

@ -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<Ui::BoxContent> VerifyPhoneBox(
tr::lng_passport_confirm_phone(
tr::now,
lt_phone,
App::formatPhone(phone)),
Ui::FormatPhone(phone)),
codeLength,
submit,
nullptr,

View File

@ -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<VerticalLayout*> layout) {
tr::lng_payments_info_phone(),
(_information.phone.isEmpty()
? QString()
: App::formatPhone(_information.phone)),
: Ui::FormatPhone(_information.phone)),
&st::paymentsIconPhone,
[=] { _delegate->panelEditPhone(); });
}

View File

@ -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<PeerListRow> 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()) {

View File

@ -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);

View File

@ -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 <QRegularExpression>
#include <QtCore/QLocale>
#include <locale>
#include <sstream>
@ -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

View File

@ -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 = "";

View File

@ -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();
}