From f9976005f743d3f31a385562e34b8bcef4fb5902 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 18 Oct 2021 19:32:50 +0300 Subject: [PATCH] Moved ShowPhoneBannedError to separated file. --- Telegram/CMakeLists.txt | 2 + .../SourceFiles/boxes/change_phone_box.cpp | 6 +- .../SourceFiles/boxes/confirm_phone_box.cpp | 41 ----------- .../SourceFiles/boxes/confirm_phone_box.h | 2 - .../SourceFiles/boxes/phone_banned_box.cpp | 68 +++++++++++++++++++ Telegram/SourceFiles/boxes/phone_banned_box.h | 20 ++++++ Telegram/SourceFiles/intro/intro_phone.cpp | 4 +- 7 files changed, 95 insertions(+), 48 deletions(-) create mode 100644 Telegram/SourceFiles/boxes/phone_banned_box.cpp create mode 100644 Telegram/SourceFiles/boxes/phone_banned_box.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 395eaebe41..b1ea783c3b 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -223,6 +223,8 @@ PRIVATE boxes/peer_lists_box.h boxes/passcode_box.cpp boxes/passcode_box.h + boxes/phone_banned_box.cpp + boxes/phone_banned_box.h boxes/rate_call_box.cpp boxes/rate_call_box.h boxes/self_destruction_box.cpp diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index a43e5e85d0..52cd43c86f 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -9,14 +9,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "lang/lang_keys.h" #include "ui/widgets/labels.h" -#include "ui/widgets/input_fields.h" +#include "ui/widgets/sent_code_field.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" #include "boxes/confirm_box.h" +#include "boxes/phone_banned_box.h" #include "countries/countries_instance.h" // Countries::ExtractPhoneCode. #include "main/main_session.h" #include "data/data_session.h" @@ -231,7 +231,7 @@ void ChangePhoneBox::EnterPhone::sendPhoneFail(const MTP::Error &error, const QS } else if (error.type() == qstr("PHONE_NUMBER_INVALID")) { showError(tr::lng_bad_phone(tr::now)); } else if (error.type() == qstr("PHONE_NUMBER_BANNED")) { - ShowPhoneBannedError(phoneNumber); + Ui::ShowPhoneBannedError(&_controller->window(), phoneNumber); } else if (error.type() == qstr("PHONE_NUMBER_OCCUPIED")) { _controller->show( Box( diff --git a/Telegram/SourceFiles/boxes/confirm_phone_box.cpp b/Telegram/SourceFiles/boxes/confirm_phone_box.cpp index cf531a1094..7aa5453a08 100644 --- a/Telegram/SourceFiles/boxes/confirm_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_phone_box.cpp @@ -27,49 +27,8 @@ namespace { object_ptr CurrentConfirmPhoneBox = { nullptr }; -void SendToBannedHelp(const QString &phone) { - const auto version = QString::fromLatin1(AppVersionStr) - + (cAlphaVersion() - ? qsl(" alpha %1").arg(cAlphaVersion()) - : (AppBetaVersion ? " beta" : "")); - - const auto subject = qsl("Banned phone number: ") + phone; - - const auto body = qsl("\ -I'm trying to use my mobile phone number: ") + phone + qsl("\n\ -But Telegram says it's banned. Please help.\n\ -\n\ -App version: ") + version + qsl("\n\ -OS version: ") + Platform::SystemVersionPretty() + qsl("\n\ -Locale: ") + Platform::SystemLanguage(); - - const auto url = "mailto:?to=" - + qthelp::url_encode("login@stel.com") - + "&subject=" - + qthelp::url_encode(subject) - + "&body=" - + qthelp::url_encode(body); - - UrlClickHandler::Open(url); -} - } // namespace -void ShowPhoneBannedError(const QString &phone) { - const auto box = std::make_shared>(); - const auto close = [=] { - if (*box) { - (*box)->closeBox(); - } - }; - *box = Ui::show(Box( - tr::lng_signin_banned_text(tr::now), - tr::lng_box_ok(tr::now), - tr::lng_signin_banned_help(tr::now), - close, - [=] { SendToBannedHelp(phone); close(); })); -} - void ConfirmPhoneBox::Start( not_null session, const QString &phone, diff --git a/Telegram/SourceFiles/boxes/confirm_phone_box.h b/Telegram/SourceFiles/boxes/confirm_phone_box.h index e5a5c193b7..fc21671a91 100644 --- a/Telegram/SourceFiles/boxes/confirm_phone_box.h +++ b/Telegram/SourceFiles/boxes/confirm_phone_box.h @@ -22,8 +22,6 @@ namespace Main { class Session; } // namespace Main -void ShowPhoneBannedError(const QString &phone); - class ConfirmPhoneBox final : public Ui::BoxContent { public: static void Start( diff --git a/Telegram/SourceFiles/boxes/phone_banned_box.cpp b/Telegram/SourceFiles/boxes/phone_banned_box.cpp new file mode 100644 index 0000000000..69a9fc44eb --- /dev/null +++ b/Telegram/SourceFiles/boxes/phone_banned_box.cpp @@ -0,0 +1,68 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "boxes/phone_banned_box.h" + +#include "boxes/confirm_box.h" +#include "core/click_handler_types.h" // UrlClickHandler +#include "base/qthelp_url.h" // qthelp::url_encode +#include "base/platform/base_platform_info.h" +#include "window/window_controller.h" +#include "lang/lang_keys.h" + +namespace Ui { + +namespace { + +void SendToBannedHelp(const QString &phone) { + const auto version = QString::fromLatin1(AppVersionStr) + + (cAlphaVersion() + ? qsl(" alpha %1").arg(cAlphaVersion()) + : (AppBetaVersion ? " beta" : "")); + + const auto subject = qsl("Banned phone number: ") + phone; + + const auto body = qsl("\ +I'm trying to use my mobile phone number: ") + phone + qsl("\n\ +But Telegram says it's banned. Please help.\n\ +\n\ +App version: ") + version + qsl("\n\ +OS version: ") + ::Platform::SystemVersionPretty() + qsl("\n\ +Locale: ") + ::Platform::SystemLanguage(); + + const auto url = "mailto:?to=" + + qthelp::url_encode("login@stel.com") + + "&subject=" + + qthelp::url_encode(subject) + + "&body=" + + qthelp::url_encode(body); + + UrlClickHandler::Open(url); +} + +} // namespace + +void ShowPhoneBannedError( + not_null controller, + const QString &phone) { + const auto box = std::make_shared>(); + const auto close = [=] { + if (*box) { + (*box)->closeBox(); + } + }; + *box = controller->show( + Box( + tr::lng_signin_banned_text(tr::now), + tr::lng_box_ok(tr::now), + tr::lng_signin_banned_help(tr::now), + close, + [=] { SendToBannedHelp(phone); close(); }), + Ui::LayerOption::CloseOther); +} + +} // namespace Ui diff --git a/Telegram/SourceFiles/boxes/phone_banned_box.h b/Telegram/SourceFiles/boxes/phone_banned_box.h new file mode 100644 index 0000000000..e5048f9a80 --- /dev/null +++ b/Telegram/SourceFiles/boxes/phone_banned_box.h @@ -0,0 +1,20 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +namespace Window { +class Controller; +} // namespace Window + +namespace Ui { + +void ShowPhoneBannedError( + not_null controller, + const QString &phone); + +} // namespace Ui diff --git a/Telegram/SourceFiles/intro/intro_phone.cpp b/Telegram/SourceFiles/intro/intro_phone.cpp index ec9a3086f9..d9996acab5 100644 --- a/Telegram/SourceFiles/intro/intro_phone.cpp +++ b/Telegram/SourceFiles/intro/intro_phone.cpp @@ -20,8 +20,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_app_config.h" #include "main/main_session.h" #include "data/data_user.h" -#include "boxes/confirm_phone_box.h" #include "boxes/confirm_box.h" +#include "boxes/phone_banned_box.h" #include "core/application.h" namespace Intro { @@ -240,7 +240,7 @@ void PhoneWidget::phoneSubmitFail(const MTP::Error &error) { } else if (err == qstr("PHONE_NUMBER_INVALID")) { // show error showPhoneError(tr::lng_bad_phone()); } else if (err == qstr("PHONE_NUMBER_BANNED")) { - ShowPhoneBannedError(_sentPhone); + Ui::ShowPhoneBannedError(getData()->controller, _sentPhone); } else if (Logs::DebugEnabled()) { // internal server error showPhoneError(rpl::single(err + ": " + error.description())); } else {