2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 22:46:10 +00:00

Pass MTP::Instance to MTP::Sender.

This commit is contained in:
John Preston
2019-11-27 11:02:56 +03:00
parent a0152557ec
commit e943264823
65 changed files with 406 additions and 275 deletions

View File

@@ -170,12 +170,12 @@ QrWidget::QrWidget(
not_null<Main::Account*> account,
not_null<Data*> data)
: Step(parent, account, data)
, _api(account->mtp())
, _refreshTimer([=] { refreshCode(); }) {
setTitleText(rpl::single(QString()));
setDescriptionText(rpl::single(QString()));
setErrorCentered(true);
account->destroyStaleAuthorizationKeys();
account->mtpUpdates(
) | rpl::start_with_next([=](const MTPUpdates &updates) {
checkForTokenUpdate(updates);

View File

@@ -52,9 +52,9 @@ private:
void showToken(const QByteArray &token);
void done(const MTPauth_Authorization &authorization);
MTP::Sender _api;
rpl::event_stream<QByteArray> _qrCodes;
base::Timer _refreshTimer;
MTP::Sender _api;
mtpRequestId _requestId = 0;
bool _forceRefresh = false;

View File

@@ -177,7 +177,6 @@ private:
object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _description;
bool _errorCentered = false;
bool _errorBelowLink = false;
rpl::variable<QString> _errorText;
object_ptr<Ui::FadeWrap<Ui::FlatLabel>> _error = { nullptr };

View File

@@ -60,8 +60,6 @@ PhoneWidget::PhoneWidget(
_country->onChooseCountry(qsl("US"));
}
_changed = false;
account->destroyStaleAuthorizationKeys();
}
void PhoneWidget::resizeEvent(QResizeEvent *e) {

View File

@@ -16,6 +16,7 @@ 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 "main/main_account.h"
#include "base/openssl_help.h"
#include "styles/style_intro.h"
#include "styles/style_boxes.h"
@@ -28,6 +29,7 @@ PwdCheckWidget::PwdCheckWidget(
not_null<Main::Account*> account,
not_null<Data*> data)
: Step(parent, account, data)
, _api(account->mtp())
, _request(getData()->pwdRequest)
, _hasRecovery(getData()->hasRecovery)
, _notEmptyPassport(getData()->pwdNotEmptyPassport)
@@ -115,7 +117,7 @@ void PwdCheckWidget::activate() {
}
void PwdCheckWidget::cancelled() {
request(base::take(_sentRequest)).cancel();
_api.request(base::take(_sentRequest)).cancel();
}
void PwdCheckWidget::stopCheck() {
@@ -127,7 +129,7 @@ void PwdCheckWidget::onCheckRequest() {
if (status < 0) {
auto leftms = -status;
if (leftms >= 1000) {
request(base::take(_sentRequest)).cancel();
_api.request(base::take(_sentRequest)).cancel();
}
}
if (!_sentRequest && status == MTP::RequestSent) {
@@ -202,8 +204,8 @@ void PwdCheckWidget::checkPasswordHash() {
}
void PwdCheckWidget::requestPasswordData() {
request(base::take(_sentRequest)).cancel();
_sentRequest = request(
_api.request(base::take(_sentRequest)).cancel();
_sentRequest = _api.request(
MTPaccount_GetPassword()
).done([=](const MTPaccount_Password &result) {
_sentRequest = 0;
@@ -225,7 +227,7 @@ void PwdCheckWidget::passwordChecked() {
return serverError();
}
_request.id = 0;
_sentRequest = request(
_sentRequest = _api.request(
MTPauth_CheckPassword(check.result)
).done([=](const MTPauth_Authorization &result) {
pwdSubmitDone(false, result);
@@ -289,7 +291,7 @@ void PwdCheckWidget::recoverStartFail(const RPCError &error) {
void PwdCheckWidget::onToRecover() {
if (_hasRecovery) {
if (_sentRequest) {
request(base::take(_sentRequest)).cancel();
_api.request(base::take(_sentRequest)).cancel();
}
hideError();
_toRecover->hide();
@@ -301,7 +303,7 @@ void PwdCheckWidget::onToRecover() {
_codeField->setFocus();
updateDescriptionText();
if (_emailPattern.isEmpty()) {
request(
_api.request(
MTPauth_RequestPasswordRecovery()
).done([=](const MTPauth_PasswordRecovery &result) {
recoverStarted(result);
@@ -320,7 +322,7 @@ void PwdCheckWidget::onToPassword() {
void PwdCheckWidget::showReset() {
if (_sentRequest) {
request(base::take(_sentRequest)).cancel();
_api.request(base::take(_sentRequest)).cancel();
}
_toRecover->show();
_toPassword->hide();
@@ -355,7 +357,7 @@ void PwdCheckWidget::submit() {
return;
}
const auto send = crl::guard(this, [=] {
_sentRequest = request(
_sentRequest = _api.request(
MTPauth_RecoverPassword(MTP_string(code))
).done([=](const MTPauth_Authorization &result) {
pwdSubmitDone(true, result);

View File

@@ -21,7 +21,7 @@ class LinkButton;
namespace Intro {
namespace details {
class PwdCheckWidget : public Step, private MTP::Sender {
class PwdCheckWidget : public Step {
Q_OBJECT
public:
@@ -67,6 +67,7 @@ private:
void passwordChecked();
void serverError();
MTP::Sender _api;
Core::CloudPasswordCheckRequest _request;
crl::time _lastSrpIdInvalidTime = 0;
bytes::vector _passwordHash;

View File

@@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "intro/intro_qr.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "main/main_account.h"
namespace Intro {
namespace details {
@@ -27,6 +28,7 @@ StartWidget::StartWidget(
}
void StartWidget::submit() {
account().destroyStaleAuthorizationKeys();
goNext<QrWidget>();
}

View File

@@ -50,30 +50,42 @@ Widget::Widget(QWidget *parent, not_null<Main::Account*> account)
st::defaultBoxButton))
, _next(
this,
object_ptr<Ui::RoundButton>(
object_ptr<Ui::RoundButton>(this, nullptr, st::introNextButton))
, _connecting(std::make_unique<Window::ConnectionState>(
this,
nullptr,
st::introNextButton)) {
rpl::single(true))) {
appendStep(new StartWidget(this, _account, getData()));
fixOrder();
getData()->country = Platform::SystemCountry();
_account->mtpValue(
) | rpl::start_with_next([=](MTP::Instance *instance) {
if (instance) {
_api.emplace(instance);
createLanguageLink();
} else {
_api.reset();
}
}, lifetime());
subscribe(Lang::CurrentCloudManager().firstLanguageSuggestion(), [=] {
createLanguageLink();
});
_back->entity()->setClickedCallback([=] {
historyMove(Direction::Back);
});
_back->hide(anim::type::instant);
_next->entity()->setClickedCallback([this] { getStep()->submit(); });
_next->entity()->setClickedCallback([=] { getStep()->submit(); });
_settings->entity()->setClickedCallback([] { App::wnd()->showSettings(); });
getNearestDC();
setupConnectingWidget();
appendStep(new StartWidget(this, _account, getData()));
fixOrder();
subscribe(Lang::CurrentCloudManager().firstLanguageSuggestion(), [this] { createLanguageLink(); });
createLanguageLink();
if (_changeLanguage) _changeLanguage->finishAnimating();
if (_changeLanguage) {
_changeLanguage->finishAnimating();
}
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
@@ -98,12 +110,6 @@ Widget::Widget(QWidget *parent, not_null<Main::Account*> account)
}
}
void Widget::setupConnectingWidget() {
_connecting = std::make_unique<Window::ConnectionState>(
this,
rpl::single(true));
}
void Widget::refreshLang() {
_changeLanguage.destroy();
createLanguageLink();
@@ -111,9 +117,13 @@ void Widget::refreshLang() {
}
void Widget::createLanguageLink() {
if (_changeLanguage) return;
if (_changeLanguage) {
return;
}
auto createLink = [this](const QString &text, const QString &languageId) {
const auto createLink = [=](
const QString &text,
const QString &languageId) {
_changeLanguage.create(
this,
object_ptr<Ui::LinkButton>(this, text));
@@ -134,8 +144,8 @@ void Widget::createLanguageLink() {
createLink(
Lang::GetOriginalValue(tr::lng_switch_to_this.base),
defaultId);
} else if (!suggested.isEmpty() && suggested != currentId) {
request(MTPlangpack_GetStrings(
} else if (!suggested.isEmpty() && suggested != currentId && _api) {
_api->request(MTPlangpack_GetStrings(
MTP_string(Lang::CloudLangPackName()),
MTP_string(suggested),
MTP_vector<MTPstring>(1, MTP_string("lng_switch_to_this"))
@@ -339,18 +349,24 @@ void Widget::acceptTerms(Fn<void()> callback) {
}
void Widget::resetAccount() {
if (_resetRequest) return;
if (_resetRequest || !_api) {
return;
}
Ui::show(Box<ConfirmBox>(tr::lng_signin_sure_reset(tr::now), tr::lng_signin_reset(tr::now), st::attentionBoxButton, crl::guard(this, [this] {
if (_resetRequest) return;
_resetRequest = request(MTPaccount_DeleteAccount(MTP_string("Forgot password"))).done([this](const MTPBool &result) {
if (_resetRequest) {
return;
}
_resetRequest = _api->request(MTPaccount_DeleteAccount(
MTP_string("Forgot password")
)).done([=](const MTPBool &result) {
_resetRequest = 0;
Ui::hideLayer();
moveToStep(
new SignupWidget(this, _account, getData()),
Direction::Replace);
}).fail([this](const RPCError &error) {
}).fail([=](const RPCError &error) {
_resetRequest = 0;
const auto &type = error.type();
@@ -410,8 +426,12 @@ void Widget::resetAccount() {
}
void Widget::getNearestDC() {
request(MTPhelp_GetNearestDc()).done([this](const MTPNearestDc &result) {
auto &nearest = result.c_nearestDc();
if (!_api) {
return;
}
_api->request(MTPhelp_GetNearestDc(
)).done([=](const MTPNearestDc &result) {
const auto &nearest = result.c_nearestDc();
DEBUG_LOG(("Got nearest dc, country: %1, nearest: %2, this: %3"
).arg(qs(nearest.vcountry())
).arg(nearest.vnearest_dc().v

View File

@@ -72,10 +72,7 @@ class Step;
} // namespace details
class Widget
: public Ui::RpWidget
, private MTP::Sender
, private base::Subscriber {
class Widget : public Ui::RpWidget, private base::Subscriber {
public:
Widget(QWidget *parent, not_null<Main::Account*> account);
@@ -91,7 +88,6 @@ protected:
void keyPressEvent(QKeyEvent *e) override;
private:
void setupConnectingWidget();
void refreshLang();
void animationCallback();
void createLanguageLink();
@@ -127,7 +123,8 @@ private:
void getNearestDC();
void showTerms(Fn<void()> callback);
not_null<Main::Account*> _account;
const not_null<Main::Account*> _account;
std::optional<MTP::Sender> _api;
Ui::Animations::Simple _a_show;
bool _showBack = false;