diff --git a/Telegram/SourceFiles/api/api_confirm_phone.cpp b/Telegram/SourceFiles/api/api_confirm_phone.cpp index f94bf0a6a9..677d6d13c0 100644 --- a/Telegram/SourceFiles/api/api_confirm_phone.cpp +++ b/Telegram/SourceFiles/api/api_confirm_phone.cpp @@ -58,6 +58,10 @@ void ConfirmPhone::resolve( }, [&](const MTPDauth_sentCodeTypeSetUpEmailRequired &) { return bad("SetUpEmailRequired"); }); + const auto fragmentUrl = data.vtype().match([]( + const MTPDauth_sentCodeTypeFragmentSms &data) { + return qs(data.vurl()); + }, [](const auto &) { return QString(); }); const auto phoneHash = qs(data.vphone_code_hash()); const auto timeout = [&]() -> std::optional { if (const auto nextType = data.vnext_type()) { @@ -70,6 +74,7 @@ void ConfirmPhone::resolve( auto box = Box( phone, sentCodeLength, + fragmentUrl, timeout); const auto boxWeak = Ui::MakeWeak(box.data()); box->resendRequests( diff --git a/Telegram/SourceFiles/ui/boxes/confirm_phone_box.cpp b/Telegram/SourceFiles/ui/boxes/confirm_phone_box.cpp index a2b51ac502..9fab7f4a59 100644 --- a/Telegram/SourceFiles/ui/boxes/confirm_phone_box.cpp +++ b/Telegram/SourceFiles/ui/boxes/confirm_phone_box.cpp @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "ui/boxes/confirm_phone_box.h" +#include "core/file_utilities.h" #include "ui/boxes/confirm_box.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" @@ -22,10 +23,20 @@ ConfirmPhoneBox::ConfirmPhoneBox( QWidget*, const QString &phone, int codeLength, + const QString &openUrl, std::optional timeout) : _phone(phone) , _sentCodeLength(codeLength) -, _call([this] { sendCall(); }, [this] { update(); }) { +, _call([=] { sendCall(); }, [=] { update(); }) { + if (!openUrl.isEmpty()) { + _fragment.create( + this, + tr::lng_intro_fragment_button(), + st::fragmentBoxButton); + _fragment->setClickedCallback([=] { File::OpenUrl(openUrl); }); + _fragment->setTextTransform( + Ui::RoundButton::TextTransform::NoTransform); + } if (timeout) { _call.setStatus({ Ui::SentCodeCall::State::Waiting, *timeout }); } @@ -59,7 +70,8 @@ void ConfirmPhoneBox::prepare() { + _code->height() + st::usernameSkip + _about->height() - + st::usernameSkip); + + st::usernameSkip + + (_fragment ? (_fragment->height() + fragmentSkip()) : 0)); connect(_code, &Ui::InputField::submitted, [=] { sendCode(); }); @@ -132,15 +144,27 @@ void ConfirmPhoneBox::resizeEvent(QResizeEvent *e) { _code->height()); _code->moveToLeft(st::usernamePadding.left(), st::usernamePadding.top()); - _about->moveToLeft( - st::usernamePadding.left(), - _code->y() + _code->height() + st::usernameSkip); + if (_fragment) { + _fragment->setFullWidth(_code->width()); + _fragment->moveToLeft( + (width() - _fragment->width()) / 2, + _code->y() + _code->height() + st::usernameSkip); + } + + const auto aboutTop = _fragment + ? (_fragment->y() + _fragment->height() + fragmentSkip()) + : (_code->y() + _code->height() + st::usernameSkip); + _about->moveToLeft(st::usernamePadding.left(), aboutTop); } void ConfirmPhoneBox::setInnerFocus() { _code->setFocusFast(); } +int ConfirmPhoneBox::fragmentSkip() const { + return st::usernamePadding.bottom(); +} + rpl::producer ConfirmPhoneBox::checkRequests() const { return _checkRequests.events(); } diff --git a/Telegram/SourceFiles/ui/boxes/confirm_phone_box.h b/Telegram/SourceFiles/ui/boxes/confirm_phone_box.h index ce620d86a2..43eefc529d 100644 --- a/Telegram/SourceFiles/ui/boxes/confirm_phone_box.h +++ b/Telegram/SourceFiles/ui/boxes/confirm_phone_box.h @@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace Ui { class FlatLabel; +class RoundButton; class ConfirmPhoneBox final : public Ui::BoxContent { public: @@ -20,6 +21,7 @@ public: QWidget*, const QString &phone, int codeLength, + const QString &openUrl, std::optional timeout); [[nodiscard]] rpl::producer checkRequests() const; @@ -40,6 +42,8 @@ private: void sendCall(); void checkPhoneAndHash(); + [[nodiscard]] int fragmentSkip() const; + QString getPhone() const; void showError(const QString &error); @@ -54,6 +58,7 @@ private: object_ptr _about = { nullptr }; object_ptr _code = { nullptr }; + object_ptr _fragment = { nullptr }; QString _error; Ui::SentCodeCall _call;