From 4379fa22973fa3e65c14cb94cde6e4b9b1e79749 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 5 Jun 2019 20:43:21 +0300 Subject: [PATCH] Handle PHONE_NUMBER_BANNED in ChangePhoneBox. --- .../SourceFiles/boxes/change_phone_box.cpp | 13 +++++- .../SourceFiles/boxes/confirm_phone_box.cpp | 45 +++++++++++++++++++ .../SourceFiles/boxes/confirm_phone_box.h | 2 + Telegram/SourceFiles/intro/introcode.cpp | 4 +- Telegram/SourceFiles/intro/introphone.cpp | 38 +--------------- Telegram/SourceFiles/intro/introsignup.cpp | 9 ++-- 6 files changed, 69 insertions(+), 42 deletions(-) diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index 52049527d..de90dbcec 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -201,8 +201,16 @@ bool ChangePhoneBox::EnterPhone::sendPhoneFail(const QString &phoneNumber, const return false; } else if (error.type() == qstr("PHONE_NUMBER_INVALID")) { errorText = lang(lng_bad_phone); + } else if (error.type() == qstr("PHONE_NUMBER_BANNED")) { + ShowPhoneBannedError(phoneNumber); + _requestId = 0; + return true; } else if (error.type() == qstr("PHONE_NUMBER_OCCUPIED")) { - Ui::show(Box(lng_change_phone_occupied(lt_phone, App::formatPhone(phoneNumber)), lang(lng_box_ok))); + Ui::show(Box( + lng_change_phone_occupied( + lt_phone, + App::formatPhone(phoneNumber)), + lang(lng_box_ok))); _requestId = 0; return true; } @@ -314,7 +322,8 @@ bool ChangePhoneBox::EnterCode::sendCodeFail(const RPCError &error) { return false; } else if (error.type() == qstr("PHONE_CODE_EMPTY") || error.type() == qstr("PHONE_CODE_INVALID")) { errorText = lang(lng_bad_code); - } else if (error.type() == qstr("PHONE_CODE_EXPIRED")) { + } else if (error.type() == qstr("PHONE_CODE_EXPIRED") + || error.type() == qstr("PHONE_NUMBER_BANNED")) { closeBox(); // Go back to phone input. _requestId = 0; return true; diff --git a/Telegram/SourceFiles/boxes/confirm_phone_box.cpp b/Telegram/SourceFiles/boxes/confirm_phone_box.cpp index 91ba39590..d2a3fc20c 100644 --- a/Telegram/SourceFiles/boxes/confirm_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/confirm_phone_box.cpp @@ -12,6 +12,9 @@ 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 "core/click_handler_types.h" // UrlClickHandler +#include "base/qthelp_url.h" // qthelp::url_encode +#include "platform/platform_info.h" // Platform::SystemVersionPretty #include "mainwidget.h" #include "lang/lang_keys.h" @@ -19,8 +22,50 @@ 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( + lang(lng_signin_banned_text), + lang(lng_box_ok), + lang(lng_signin_banned_help), + close, + [=] { SendToBannedHelp(phone); close(); })); + +} + SentCodeField::SentCodeField( QWidget *parent, const style::InputField &st, diff --git a/Telegram/SourceFiles/boxes/confirm_phone_box.h b/Telegram/SourceFiles/boxes/confirm_phone_box.h index 9eb443f45..839181db6 100644 --- a/Telegram/SourceFiles/boxes/confirm_phone_box.h +++ b/Telegram/SourceFiles/boxes/confirm_phone_box.h @@ -16,6 +16,8 @@ class InputField; class FlatLabel; } // namespace Ui +void ShowPhoneBannedError(const QString &phone); + class SentCodeField : public Ui::InputField { public: SentCodeField( diff --git a/Telegram/SourceFiles/intro/introcode.cpp b/Telegram/SourceFiles/intro/introcode.cpp index 0774dd7c1..fcd8d64c4 100644 --- a/Telegram/SourceFiles/intro/introcode.cpp +++ b/Telegram/SourceFiles/intro/introcode.cpp @@ -231,7 +231,9 @@ bool CodeWidget::codeSubmitFail(const RPCError &error) { stopCheck(); _sentRequest = 0; auto &err = error.type(); - if (err == qstr("PHONE_NUMBER_INVALID") || err == qstr("PHONE_CODE_EXPIRED")) { // show error + if (err == qstr("PHONE_NUMBER_INVALID") + || err == qstr("PHONE_CODE_EXPIRED") + || err == qstr("PHONE_NUMBER_BANNED")) { // show error goBack(); return true; } else if (err == qstr("PHONE_CODE_EMPTY") || err == qstr("PHONE_CODE_INVALID")) { diff --git a/Telegram/SourceFiles/intro/introphone.cpp b/Telegram/SourceFiles/intro/introphone.cpp index a00872ae0..56e9240c7 100644 --- a/Telegram/SourceFiles/intro/introphone.cpp +++ b/Telegram/SourceFiles/intro/introphone.cpp @@ -13,41 +13,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" #include "ui/wrap/fade_wrap.h" -#include "core/click_handler_types.h" +#include "boxes/confirm_phone_box.h" #include "boxes/confirm_box.h" -#include "base/qthelp_url.h" -#include "platform/platform_info.h" #include "core/application.h" namespace Intro { 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); -} - bool AllowPhoneAttempt(const QString &phone) { const auto digits = ranges::count_if( phone, @@ -254,13 +226,7 @@ bool PhoneWidget::phoneSubmitFail(const RPCError &error) { showPhoneError(langFactory(lng_bad_phone)); return true; } else if (err == qstr("PHONE_NUMBER_BANNED")) { - const auto phone = _sentPhone; - Ui::show(Box( - lang(lng_signin_banned_text), - lang(lng_box_ok), - lang(lng_signin_banned_help), - [] { Ui::hideLayer(); }, - [phone] { SendToBannedHelp(phone); Ui::hideLayer(); })); + ShowPhoneBannedError(_sentPhone); return true; } if (Logs::DebugEnabled()) { // internal server error diff --git a/Telegram/SourceFiles/intro/introsignup.cpp b/Telegram/SourceFiles/intro/introsignup.cpp index f214da5ba..0a426b424 100644 --- a/Telegram/SourceFiles/intro/introsignup.cpp +++ b/Telegram/SourceFiles/intro/introsignup.cpp @@ -146,9 +146,12 @@ bool SignupWidget::nameSubmitFail(const RPCError &error) { if (err == qstr("PHONE_NUMBER_FLOOD")) { Ui::show(Box(lang(lng_error_phone_flood))); return true; - } else if (err == qstr("PHONE_NUMBER_INVALID") || err == qstr("PHONE_CODE_EXPIRED") || - err == qstr("PHONE_CODE_EMPTY") || err == qstr("PHONE_CODE_INVALID") || - err == qstr("PHONE_NUMBER_OCCUPIED")) { + } else if (err == qstr("PHONE_NUMBER_INVALID") + || err == qstr("PHONE_NUMBER_BANNED") + || err == qstr("PHONE_CODE_EXPIRED") + || err == qstr("PHONE_CODE_EMPTY") + || err == qstr("PHONE_CODE_INVALID") + || err == qstr("PHONE_NUMBER_OCCUPIED")) { goBack(); return true; } else if (err == "FIRSTNAME_INVALID") {