Don't change dc after qr request / phone submit.

This commit is contained in:
John Preston 2020-06-26 15:28:06 +04:00
parent 793e8c102e
commit 6960e4808a
7 changed files with 31 additions and 9 deletions

View file

@ -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());

View file

@ -179,6 +179,8 @@ QrWidget::QrWidget(
setDescriptionText(rpl::single(QString()));
setErrorCentered(true);
cancelNearestDcRequest();
account->mtpUpdates(
) | rpl::start_with_next([=](const MTPUpdates &updates) {
checkForTokenUpdate(updates);

View file

@ -502,6 +502,10 @@ void Step::setShowTermsCallback(Fn<void()> callback) {
_showTermsCallback = std::move(callback);
}
void Step::setCancelNearestDcCallback(Fn<void()> callback) {
_cancelNearestDcCallback = std::move(callback);
}
void Step::setAcceptTermsCallback(
Fn<void(Fn<void()> callback)> callback) {
_acceptTermsCallback = std::move(callback);

View file

@ -58,8 +58,8 @@ public:
void setGoCallback(
Fn<void(Step *step, StackAction action, Animate animate)> callback);
void setShowResetCallback(Fn<void()> callback);
void setShowTermsCallback(
Fn<void()> callback);
void setShowTermsCallback(Fn<void()> callback);
void setCancelNearestDcCallback(Fn<void()> callback);
void setAcceptTermsCallback(
Fn<void(Fn<void()> callback)> callback);
@ -130,6 +130,9 @@ protected:
_acceptTermsCallback(callback);
}
}
void cancelNearestDcRequest() {
if (_cancelNearestDcCallback) _cancelNearestDcCallback();
}
virtual int errorTop() const;
@ -176,6 +179,7 @@ private:
Fn<void(Step *step, StackAction action, Animate animate)> _goCallback;
Fn<void()> _showResetCallback;
Fn<void()> _showTermsCallback;
Fn<void()> _cancelNearestDcCallback;
Fn<void(Fn<void()> callback)> _acceptTermsCallback;
rpl::variable<QString> _titleText;

View file

@ -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<void()> 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())

View file

@ -167,6 +167,7 @@ private:
const not_null<Main::Account*> _account;
std::optional<MTP::Sender> _api;
mtpRequestId _nearestDcRequestId = 0;
Ui::Animations::Simple _a_show;
bool _showBack = false;

View file

@ -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) {