2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

Move MTP::Instance to Main::Account.

This commit is contained in:
John Preston
2019-07-24 10:46:23 +02:00
parent db2018c765
commit 9cf4cf6dca
32 changed files with 715 additions and 526 deletions

View File

@@ -73,7 +73,11 @@ void CodeInput::correctValue(const QString &was, int wasCursor, QString &now, in
}
}
CodeWidget::CodeWidget(QWidget *parent, Widget::Data *data) : Step(parent, data)
CodeWidget::CodeWidget(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Widget::Data*> data)
: Step(parent, account, data)
, _noTelegramCode(this, tr::lng_code_no_telegram(tr::now), st::introLink)
, _code(this, st::introCode, tr::lng_code_ph())
, _callTimer(this)
@@ -244,7 +248,7 @@ void CodeWidget::codeSubmitDone(const MTPauth_Authorization &result) {
} else {
getData()->termsLock = Window::TermsLock();
}
goReplace(new Intro::SignupWidget(parentWidget(), getData()));
goReplace<SignupWidget>();
});
}
@@ -342,7 +346,7 @@ void CodeWidget::gotPassword(const MTPaccount_Password &result) {
getData()->hasRecovery = d.is_has_recovery();
getData()->pwdHint = qs(d.vhint().value_or_empty());
getData()->pwdNotEmptyPassport = d.is_has_secure_values();
goReplace(new Intro::PwdCheckWidget(parentWidget(), getData()));
goReplace<PwdCheckWidget>();
}
void CodeWidget::submit() {

View File

@@ -39,7 +39,10 @@ class CodeWidget : public Widget::Step {
Q_OBJECT
public:
CodeWidget(QWidget *parent, Widget::Data *data);
CodeWidget(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Widget::Data*> data);
bool hasBack() const override {
return true;

View File

@@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "ui/wrap/fade_wrap.h"
#include "main/main_account.h"
#include "boxes/confirm_phone_box.h"
#include "boxes/confirm_box.h"
#include "core/application.h"
@@ -29,7 +30,11 @@ bool AllowPhoneAttempt(const QString &phone) {
} // namespace
PhoneWidget::PhoneWidget(QWidget *parent, Widget::Data *data) : Step(parent, data)
PhoneWidget::PhoneWidget(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Widget::Data*> data)
: Step(parent, account, data)
, _country(this, st::introCountry)
, _code(this, st::introCountryCode)
, _phone(this, st::introPhone)
@@ -54,7 +59,7 @@ PhoneWidget::PhoneWidget(QWidget *parent, Widget::Data *data) : Step(parent, dat
}
_changed = false;
Core::App().destroyStaleAuthorizationKeys();
account->destroyStaleAuthorizationKeys();
}
void PhoneWidget::resizeEvent(QResizeEvent *e) {
@@ -111,7 +116,7 @@ void PhoneWidget::submit() {
_checkRequest->start(1000);
_sentPhone = phone;
Core::App().mtp()->setUserPhone(_sentPhone);
account().mtp()->setUserPhone(_sentPhone);
_sentRequest = MTP::send(
MTPauth_SendCode(
MTP_string(_sentPhone),
@@ -162,7 +167,7 @@ void PhoneWidget::phoneSubmitDone(const MTPauth_SentCode &result) {
getData()->callStatus = Widget::Data::CallStatus::Disabled;
getData()->callTimeout = 0;
}
goNext(new Intro::CodeWidget(parentWidget(), getData()));
goNext<CodeWidget>();
}
bool PhoneWidget::phoneSubmitFail(const RPCError &error) {

View File

@@ -23,7 +23,10 @@ class PhoneWidget : public Widget::Step {
Q_OBJECT
public:
PhoneWidget(QWidget *parent, Widget::Data *data);
PhoneWidget(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Widget::Data*> data);
void selectCountry(const QString &country);

View File

@@ -23,8 +23,9 @@ namespace Intro {
PwdCheckWidget::PwdCheckWidget(
QWidget *parent,
Widget::Data *data)
: Step(parent, data)
not_null<Main::Account*> account,
not_null<Widget::Data*> data)
: Step(parent, account, data)
, _request(getData()->pwdRequest)
, _hasRecovery(getData()->hasRecovery)
, _notEmptyPassport(getData()->pwdNotEmptyPassport)

View File

@@ -23,7 +23,10 @@ class PwdCheckWidget : public Widget::Step, private MTP::Sender {
Q_OBJECT
public:
PwdCheckWidget(QWidget *parent, Widget::Data *data);
PwdCheckWidget(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Widget::Data*> data);
void setInnerFocus() override;
void activate() override;

View File

@@ -20,7 +20,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Intro {
SignupWidget::SignupWidget(QWidget *parent, Widget::Data *data) : Step(parent, data)
SignupWidget::SignupWidget(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Widget::Data*> data)
: Step(parent, account, data)
, _photo(
this,
tr::lng_settings_crop_profile(tr::now),

View File

@@ -21,7 +21,10 @@ class SignupWidget : public Widget::Step {
Q_OBJECT
public:
SignupWidget(QWidget *parent, Widget::Data *data);
SignupWidget(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Widget::Data*> data);
void finishInit() override;
void setInnerFocus() override;

View File

@@ -14,7 +14,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Intro {
StartWidget::StartWidget(QWidget *parent, Widget::Data *data) : Step(parent, data, true) {
StartWidget::StartWidget(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Widget::Data*> data)
: Step(parent, account, data, true) {
setMouseTracking(true);
setTitleText(rpl::single(qsl("Telegram Desktop")));
setDescriptionText(tr::lng_intro_about());
@@ -22,7 +26,7 @@ StartWidget::StartWidget(QWidget *parent, Widget::Data *data) : Step(parent, dat
}
void StartWidget::submit() {
goNext(new Intro::PhoneWidget(parentWidget(), getData()));
goNext<PhoneWidget>();
}
rpl::producer<QString> StartWidget::nextButtonText() const {

View File

@@ -19,7 +19,10 @@ namespace Intro {
class StartWidget : public Widget::Step {
public:
StartWidget(QWidget *parent, Widget::Data *data);
StartWidget(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Widget::Data*> data);
void submit() override;
rpl::producer<QString> nextButtonText() const override;

View File

@@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "intro/introcode.h"
#include "intro/introsignup.h"
#include "intro/intropwdcheck.h"
#include "main/main_account.h"
#include "mainwidget.h"
#include "apiwrap.h"
#include "mainwindow.h"
@@ -59,7 +60,9 @@ void PrepareSupportMode() {
} // namespace
Widget::Widget(QWidget *parent) : RpWidget(parent)
Widget::Widget(QWidget *parent, not_null<Main::Account*> account)
: RpWidget(parent)
, _account(account)
, _back(this, object_ptr<Ui::IconButton>(this, st::introBackButton))
, _settings(
this,
@@ -84,7 +87,7 @@ Widget::Widget(QWidget *parent) : RpWidget(parent)
getNearestDC();
setupConnectingWidget();
appendStep(new StartWidget(this, getData()));
appendStep(new StartWidget(this, _account, getData()));
fixOrder();
subscribe(Lang::CurrentCloudManager().firstLanguageSuggestion(), [this] { createLanguageLink(); });
@@ -367,11 +370,13 @@ void Widget::resetAccount() {
_resetRequest = 0;
Ui::hideLayer();
moveToStep(new SignupWidget(this, getData()), Direction::Replace);
moveToStep(
new SignupWidget(this, _account, getData()),
Direction::Replace);
}).fail([this](const RPCError &error) {
_resetRequest = 0;
auto type = error.type();
const auto &type = error.type();
if (type.startsWith(qstr("2FA_CONFIRM_WAIT_"))) {
const auto seconds = type.mid(qstr("2FA_CONFIRM_WAIT_").size()).toInt();
const auto days = (seconds + 59) / 86400;
@@ -434,7 +439,7 @@ void Widget::getNearestDC() {
).arg(qs(nearest.vcountry())
).arg(nearest.vnearest_dc().v
).arg(nearest.vthis_dc().v));
Core::App().suggestMainDcId(nearest.vnearest_dc().v);
_account->suggestMainDcId(nearest.vnearest_dc().v);
auto nearestCountry = qs(nearest.vcountry());
if (getData()->country != nearestCountry) {
getData()->country = nearestCountry;
@@ -664,16 +669,19 @@ void Widget::Step::finish(const MTPUser &user, QImage &&photo) {
Local::writeLangPack();
}
Core::App().authSessionCreate(user);
const auto account = _account;
const auto weak = base::make_weak(account.get());
account->createSession(user);
Local::writeMtpData();
App::wnd()->setupMain();
// "this" is already deleted here by creating the main widget.
if (AuthSession::Exists()) {
if (weak && account->sessionExists()) {
auto &session = account->session();
if (!photo.isNull()) {
Auth().api().uploadPeerPhoto(Auth().user(), std::move(photo));
session.api().uploadPeerPhoto(session.user(), std::move(photo));
}
if (Auth().supportMode()) {
if (session.supportMode()) {
PrepareSupportMode();
}
}
@@ -919,8 +927,13 @@ void Widget::Step::refreshError(const QString &text) {
}
}
Widget::Step::Step(QWidget *parent, Data *data, bool hasCover)
Widget::Step::Step(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Data*> data,
bool hasCover)
: RpWidget(parent)
, _account(account)
, _data(data)
, _hasCover(hasCover)
, _title(this, _hasCover ? st::introCoverTitle : st::introTitle)

View File

@@ -13,6 +13,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "window/window_lock_widgets.h"
#include "core/core_cloud_password.h"
namespace Main {
class Account;
} // namespace Main
namespace Ui {
class IconButton;
class RoundButton;
@@ -34,7 +38,7 @@ class Widget : public Ui::RpWidget, private MTP::Sender, private base::Subscribe
Q_OBJECT
public:
Widget(QWidget *parent);
Widget(QWidget *parent, not_null<Main::Account*> account);
void showAnimated(const QPixmap &bgAnimCache, bool back = false);
@@ -90,7 +94,15 @@ public:
};
class Step : public Ui::RpWidget, public RPCSender, protected base::Subscriber {
public:
Step(QWidget *parent, Data *data, bool hasCover = false);
Step(
QWidget *parent,
not_null<Main::Account*> account,
not_null<Data*> data,
bool hasCover = false);
Main::Account &account() const {
return *_account;
}
virtual void finishInit() {
}
@@ -147,19 +159,33 @@ public:
void showDescription();
void hideDescription();
Data *getData() const {
not_null<Data*> getData() const {
return _data;
}
void finish(const MTPUser &user, QImage &&photo = QImage());
void goBack() {
if (_goCallback) _goCallback(nullptr, Direction::Back);
if (_goCallback) {
_goCallback(nullptr, Direction::Back);
}
}
void goNext(Step *step) {
if (_goCallback) _goCallback(step, Direction::Forward);
template <typename StepType>
void goNext() {
if (_goCallback) {
_goCallback(
new StepType(parentWidget(), _account, _data),
Direction::Forward);
}
}
void goReplace(Step *step) {
if (_goCallback) _goCallback(step, Direction::Replace);
template <typename StepType>
void goReplace() {
if (_goCallback) {
_goCallback(
new StepType(parentWidget(), _account, _data),
Direction::Replace);
}
}
void showResetButton() {
if (_showResetCallback) _showResetCallback();
@@ -190,9 +216,6 @@ public:
void updateLabelsPosition();
void paintContentSnapshot(Painter &p, const QPixmap &snapshot, float64 alpha, float64 howMuchHidden);
void refreshError(const QString &text);
void refreshTitle();
void refreshDescription();
void refreshLang();
CoverAnimation prepareCoverAnimation(Step *step);
QPixmap prepareContentSnapshot();
@@ -202,7 +225,9 @@ public:
void prepareCoverMask();
void paintCover(Painter &p, int top);
Data *_data = nullptr;
const not_null<Main::Account*> _account;
const not_null<Data*> _data;
bool _hasCover = false;
Fn<void(Step *step, Direction direction)> _goCallback;
Fn<void()> _showResetCallback;
@@ -233,7 +258,7 @@ private:
void createLanguageLink();
void updateControlsGeometry();
Data *getData() {
not_null<Data*> getData() {
return &_data;
}
@@ -260,6 +285,8 @@ private:
void getNearestDC();
void showTerms(Fn<void()> callback);
not_null<Main::Account*> _account;
Ui::Animations::Simple _a_show;
bool _showBack = false;
QPixmap _cacheUnder, _cacheOver;