From c6e1b144290ec7697174af8c1e148847dde8a648 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Mon, 18 Oct 2021 19:11:28 +0300 Subject: [PATCH] Added Window::SessionController to ChangePhoneBox. --- .../SourceFiles/boxes/change_phone_box.cpp | 54 +++++++++++-------- Telegram/SourceFiles/boxes/change_phone_box.h | 10 ++-- .../settings/settings_information.cpp | 2 +- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/Telegram/SourceFiles/boxes/change_phone_box.cpp b/Telegram/SourceFiles/boxes/change_phone_box.cpp index b63d7fba6..a43e5e85d 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.cpp +++ b/Telegram/SourceFiles/boxes/change_phone_box.cpp @@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_user.h" #include "mtproto/sender.h" #include "apiwrap.h" +#include "window/window_session_controller.h" #include "styles/style_layers.h" #include "styles/style_boxes.h" @@ -67,7 +68,7 @@ void createErrorLabel( class ChangePhoneBox::EnterPhone : public Ui::BoxContent { public: - EnterPhone(QWidget*, not_null session); + EnterPhone(QWidget*, not_null controller); void setInnerFocus() override { _phone->setFocusFast(); @@ -85,7 +86,7 @@ private: showError(QString()); } - const not_null _session; + const not_null _controller; MTP::Sender _api; object_ptr _phone = { nullptr }; @@ -139,9 +140,9 @@ private: ChangePhoneBox::EnterPhone::EnterPhone( QWidget*, - not_null session) -: _session(session) -, _api(&session->mtp()) { + not_null controller) +: _controller(controller) +, _api(&controller->session().mtp()) { } void ChangePhoneBox::EnterPhone::prepare() { @@ -152,7 +153,7 @@ void ChangePhoneBox::EnterPhone::prepare() { this, st::defaultInputField, tr::lng_change_phone_new_title(), - Countries::ExtractPhoneCode(_session->user()->phone()), + Countries::ExtractPhoneCode(_controller->session().user()->phone()), phoneValue); _phone->resize(st::boxWidth - 2 * st::boxPadding.left(), _phone->height()); @@ -213,9 +214,9 @@ void ChangePhoneBox::EnterPhone::sendPhoneDone( callTimeout = data.vtimeout().value_or(60); } } - Ui::show( + _controller->show( Box( - _session, + &_controller->session(), phoneNumber, phoneCodeHash, codeLength, @@ -232,12 +233,14 @@ void ChangePhoneBox::EnterPhone::sendPhoneFail(const MTP::Error &error, const QS } else if (error.type() == qstr("PHONE_NUMBER_BANNED")) { ShowPhoneBannedError(phoneNumber); } else if (error.type() == qstr("PHONE_NUMBER_OCCUPIED")) { - Ui::show(Box( - tr::lng_change_phone_occupied( - tr::now, - lt_phone, - Ui::FormatPhone(phoneNumber)), - tr::lng_box_ok(tr::now))); + _controller->show( + Box( + tr::lng_change_phone_occupied( + tr::now, + lt_phone, + Ui::FormatPhone(phoneNumber)), + tr::lng_box_ok(tr::now)), + Ui::LayerOption::CloseOther); } else { showError(Lang::Hard::ServerError()); } @@ -371,18 +374,25 @@ void ChangePhoneBox::EnterCode::sendCodeFail(const MTP::Error &error) { } } -ChangePhoneBox::ChangePhoneBox(QWidget*, not_null session) -: _session(session) { +ChangePhoneBox::ChangePhoneBox( + QWidget*, + not_null controller) +: _controller(controller) { } void ChangePhoneBox::prepare() { - const auto session = _session; - setTitle(tr::lng_change_phone_title()); - addButton(tr::lng_change_phone_button(), [=] { - Ui::show(Box(tr::lng_change_phone_warning(tr::now), [=] { - Ui::show(Box(session)); - })); + addButton(tr::lng_change_phone_button(), [=, controller = _controller] { + auto callback = [=] { + controller->show( + Box(controller), + Ui::LayerOption::CloseOther); + }; + controller->show( + Box( + tr::lng_change_phone_warning(tr::now), + std::move(callback)), + Ui::LayerOption::CloseOther); }); addButton(tr::lng_cancel(), [this] { closeBox(); diff --git a/Telegram/SourceFiles/boxes/change_phone_box.h b/Telegram/SourceFiles/boxes/change_phone_box.h index 23a2feca1..ee34b7776 100644 --- a/Telegram/SourceFiles/boxes/change_phone_box.h +++ b/Telegram/SourceFiles/boxes/change_phone_box.h @@ -9,13 +9,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/abstract_box.h" -namespace Main { -class Session; -} // namespace Main +namespace Window { +class SessionController; +} // namespace Window class ChangePhoneBox : public Ui::BoxContent { public: - ChangePhoneBox(QWidget*, not_null session); + ChangePhoneBox(QWidget*, not_null controller); protected: void prepare() override; @@ -26,7 +26,7 @@ private: class EnterPhone; class EnterCode; - const not_null _session; + const not_null _controller; }; diff --git a/Telegram/SourceFiles/settings/settings_information.cpp b/Telegram/SourceFiles/settings/settings_information.cpp index 7fa38c982..b98c858f3 100644 --- a/Telegram/SourceFiles/settings/settings_information.cpp +++ b/Telegram/SourceFiles/settings/settings_information.cpp @@ -214,7 +214,7 @@ void SetupRows( tr::lng_settings_phone_label(), Info::Profile::PhoneValue(self), tr::lng_profile_copy_phone(tr::now), - [=] { controller->show(Box(session)); }, + [=] { controller->show(Box(controller)); }, st::settingsInfoPhone); auto username = Info::Profile::UsernameValue(self);