diff --git a/Telegram/SourceFiles/intro/intro_phone.cpp b/Telegram/SourceFiles/intro/intro_phone.cpp index 2b66c5316..13aae8323 100644 --- a/Telegram/SourceFiles/intro/intro_phone.cpp +++ b/Telegram/SourceFiles/intro/intro_phone.cpp @@ -132,7 +132,9 @@ void PhoneWidget::phoneChanged() { } void PhoneWidget::submit() { - if (_sentRequest || isHidden()) return; + if (_sentRequest || isHidden()) { + return; + } const auto phone = fullNumber(); if (!AllowPhoneAttempt(phone)) { @@ -141,6 +143,8 @@ void PhoneWidget::submit() { return; } + cancelNearestDcRequest(); + // Check if such account is authorized already. const auto digitsOnly = [](QString value) { return value.replace(QRegularExpression("[^0-9]"), QString()); diff --git a/Telegram/SourceFiles/intro/intro_qr.cpp b/Telegram/SourceFiles/intro/intro_qr.cpp index 63368fa4e..99d168b29 100644 --- a/Telegram/SourceFiles/intro/intro_qr.cpp +++ b/Telegram/SourceFiles/intro/intro_qr.cpp @@ -179,6 +179,8 @@ QrWidget::QrWidget( setDescriptionText(rpl::single(QString())); setErrorCentered(true); + cancelNearestDcRequest(); + account->mtpUpdates( ) | rpl::start_with_next([=](const MTPUpdates &updates) { checkForTokenUpdate(updates); diff --git a/Telegram/SourceFiles/intro/intro_step.cpp b/Telegram/SourceFiles/intro/intro_step.cpp index cfe376aea..b87370bbc 100644 --- a/Telegram/SourceFiles/intro/intro_step.cpp +++ b/Telegram/SourceFiles/intro/intro_step.cpp @@ -502,6 +502,10 @@ void Step::setShowTermsCallback(Fn callback) { _showTermsCallback = std::move(callback); } +void Step::setCancelNearestDcCallback(Fn callback) { + _cancelNearestDcCallback = std::move(callback); +} + void Step::setAcceptTermsCallback( Fn callback)> callback) { _acceptTermsCallback = std::move(callback); diff --git a/Telegram/SourceFiles/intro/intro_step.h b/Telegram/SourceFiles/intro/intro_step.h index 4e9d0ee90..bc9548800 100644 --- a/Telegram/SourceFiles/intro/intro_step.h +++ b/Telegram/SourceFiles/intro/intro_step.h @@ -58,8 +58,8 @@ public: void setGoCallback( Fn callback); void setShowResetCallback(Fn callback); - void setShowTermsCallback( - Fn callback); + void setShowTermsCallback(Fn callback); + void setCancelNearestDcCallback(Fn callback); void setAcceptTermsCallback( Fn callback)> callback); @@ -130,6 +130,9 @@ protected: _acceptTermsCallback(callback); } } + void cancelNearestDcRequest() { + if (_cancelNearestDcCallback) _cancelNearestDcCallback(); + } virtual int errorTop() const; @@ -176,6 +179,7 @@ private: Fn _goCallback; Fn _showResetCallback; Fn _showTermsCallback; + Fn _cancelNearestDcCallback; Fn callback)> _acceptTermsCallback; rpl::variable _titleText; diff --git a/Telegram/SourceFiles/intro/intro_widget.cpp b/Telegram/SourceFiles/intro/intro_widget.cpp index a79cd45a4..2750cffb7 100644 --- a/Telegram/SourceFiles/intro/intro_widget.cpp +++ b/Telegram/SourceFiles/intro/intro_widget.cpp @@ -65,6 +65,8 @@ Widget::Widget( rpl::single(true))) { Core::App().setDefaultFloatPlayerDelegate(floatPlayerDelegate()); + getNearestDC(); + switch (point) { case EnterPoint::Start: appendStep(new StartWidget(this, _account, getData())); @@ -104,8 +106,6 @@ Widget::Widget( _settings->entity()->setClickedCallback([] { App::wnd()->showSettings(); }); - getNearestDC(); - if (_changeLanguage) { _changeLanguage->finishAnimating(); } @@ -378,9 +378,14 @@ void Widget::appendStep(Step *step) { step->setShowResetCallback([=] { showResetButton(); }); - step->setShowTermsCallback([=]() { + step->setShowTermsCallback([=] { showTerms(); }); + step->setCancelNearestDcCallback([=] { + if (_api) { + _api->request(base::take(_nearestDcRequestId)).cancel(); + } + }); step->setAcceptTermsCallback([=](Fn callback) { acceptTerms(callback); }); @@ -519,8 +524,9 @@ void Widget::getNearestDC() { if (!_api) { return; } - _api->request(MTPhelp_GetNearestDc( + _nearestDcRequestId = _api->request(MTPhelp_GetNearestDc( )).done([=](const MTPNearestDc &result) { + _nearestDcRequestId = 0; const auto &nearest = result.c_nearestDc(); DEBUG_LOG(("Got nearest dc, country: %1, nearest: %2, this: %3" ).arg(qs(nearest.vcountry()) diff --git a/Telegram/SourceFiles/intro/intro_widget.h b/Telegram/SourceFiles/intro/intro_widget.h index 5cfffa2f1..001409dfc 100644 --- a/Telegram/SourceFiles/intro/intro_widget.h +++ b/Telegram/SourceFiles/intro/intro_widget.h @@ -167,6 +167,7 @@ private: const not_null _account; std::optional _api; + mtpRequestId _nearestDcRequestId = 0; Ui::Animations::Simple _a_show; bool _showBack = false; diff --git a/Telegram/SourceFiles/mtproto/mtp_instance.cpp b/Telegram/SourceFiles/mtproto/mtp_instance.cpp index b2461cc10..3725c4a8a 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.cpp +++ b/Telegram/SourceFiles/mtproto/mtp_instance.cpp @@ -417,8 +417,9 @@ void Instance::Private::setGoodProxyDomain( } void Instance::Private::suggestMainDcId(DcId mainDcId) { - if (_mainDcIdForced) return; - setMainDcId(mainDcId); + if (!_mainDcIdForced) { + setMainDcId(mainDcId); + } } void Instance::Private::setMainDcId(DcId mainDcId) {