From ea86433be5f117342df694d92dbee225ff995671 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 10 Jun 2020 18:52:44 +0400 Subject: [PATCH] Remove some activeAccount() calls. --- Telegram/SourceFiles/boxes/connection_box.cpp | 14 ++++++---- Telegram/SourceFiles/boxes/connection_box.h | 10 +++++-- .../chat_helpers/emoji_keywords.cpp | 2 +- Telegram/SourceFiles/core/application.cpp | 6 ++--- Telegram/SourceFiles/core/application.h | 2 +- Telegram/SourceFiles/core/update_checker.cpp | 2 +- .../SourceFiles/dialogs/dialogs_widget.cpp | 1 + .../SourceFiles/info/info_section_widget.cpp | 3 +++ Telegram/SourceFiles/intro/intro_widget.cpp | 1 + .../SourceFiles/lang/lang_cloud_manager.cpp | 2 +- Telegram/SourceFiles/main/main_account.cpp | 10 +++---- Telegram/SourceFiles/main/main_account.h | 4 +-- Telegram/SourceFiles/mainwidget.cpp | 1 + Telegram/SourceFiles/mainwindow.cpp | 8 +++--- .../media/player/media_player_instance.cpp | 2 +- .../media/view/media_view_overlay_widget.cpp | 3 ++- Telegram/SourceFiles/mtproto/facade.cpp | 2 +- Telegram/SourceFiles/mtproto/mtp_instance.cpp | 2 +- .../settings/settings_advanced.cpp | 10 ++++--- .../SourceFiles/settings/settings_advanced.h | 8 +++++- .../SourceFiles/settings/settings_intro.cpp | 27 ++++++++++++------- .../SourceFiles/settings/settings_intro.h | 6 ++++- .../details/storage_settings_scheme.cpp | 12 +++++---- .../storage/details/storage_settings_scheme.h | 9 +++++++ .../SourceFiles/storage/storage_account.cpp | 17 ++++++++++-- .../window/themes/window_theme.cpp | 2 +- .../window/window_connecting_widget.cpp | 18 +++++++++---- .../window/window_connecting_widget.h | 6 +++++ 28 files changed, 132 insertions(+), 58 deletions(-) diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 68be5de2e..68130f4e5 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -978,8 +978,9 @@ void ProxyBox::addLabel( } // namespace -ProxiesBoxController::ProxiesBoxController() -: _saveTimer([] { Local::writeSettings(); }) { +ProxiesBoxController::ProxiesBoxController(not_null account) +: _account(account) +, _saveTimer([] { Local::writeSettings(); }) { _list = ranges::view::all( Global::ProxiesList() ) | ranges::view::transform([&](const ProxyData &proxy) { @@ -1058,7 +1059,9 @@ void ProxiesBoxController::refreshChecker(Item &item) { const auto type = (item.data.type == Type::Http) ? Variants::Http : Variants::Tcp; - const auto mtproto = Core::App().activeAccount().mtp(); + const auto mtproto = _account->mtp(); + Assert(mtproto != nullptr); + const auto dcId = mtproto->mainDcId(); item.state = ItemState::Checking; @@ -1142,8 +1145,9 @@ void ProxiesBoxController::setupChecker(int id, const Checker &checker) { pointer->connect(pointer, &Connection::error, failed); } -object_ptr ProxiesBoxController::CreateOwningBox() { - auto controller = std::make_unique(); +object_ptr ProxiesBoxController::CreateOwningBox( + not_null account) { + auto controller = std::make_unique(account); auto box = controller->create(); Ui::AttachAsChild(box, std::move(controller)); return box; diff --git a/Telegram/SourceFiles/boxes/connection_box.h b/Telegram/SourceFiles/boxes/connection_box.h index fbefdacb5..8a7709f9c 100644 --- a/Telegram/SourceFiles/boxes/connection_box.h +++ b/Telegram/SourceFiles/boxes/connection_box.h @@ -24,18 +24,23 @@ template class Radioenum; } // namespace Ui +namespace Main { +class Account; +} // namespace Main + class ProxiesBoxController : public base::Subscriber { public: using ProxyData = MTP::ProxyData; using Type = ProxyData::Type; - ProxiesBoxController(); + explicit ProxiesBoxController(not_null account); static void ShowApplyConfirmation( Type type, const QMap &fields); - static object_ptr CreateOwningBox(); + static object_ptr CreateOwningBox( + not_null account); object_ptr create(); enum class ItemState { @@ -104,6 +109,7 @@ private: const ProxyData &proxy); void addNewItem(const ProxyData &proxy); + const not_null _account; int _idCounter = 0; std::vector _list; rpl::event_stream _views; diff --git a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp index 4878b7a09..a06b55203 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_keywords.cpp @@ -516,7 +516,7 @@ void EmojiKeywords::langPackRefreshed() { } void EmojiKeywords::handleSessionChanges() { - Core::App().activeAccount().sessionValue( + Core::App().activeAccount().sessionValue( // #TODO multi someSessionValue ) | rpl::map([](Main::Session *session) { return session ? &session->api() : nullptr; }) | rpl::start_with_next([=](ApiWrap *api) { diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index ad4eb2bfc..2174869ac 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -113,13 +113,13 @@ Application::Application(not_null launcher) _shouldLockAt = 0; }, _lifetime); - activeAccount().sessionChanges( + activeAccount().sessionChanges( // #TODO multi activeSessionValue ) | rpl::start_with_next([=](Main::Session *session) { if (_mediaView) { hideMediaView(); _mediaView->clearData(); } - if (session && !UpdaterDisabled()) { + if (session && !UpdaterDisabled()) { // #TODO multi someSessionValue UpdateChecker().setMtproto(session); } }, _lifetime); @@ -578,7 +578,7 @@ bool Application::unreadBadgeMuted() const { : false; } -bool Application::offerLangPackSwitch() const { +bool Application::offerLegacyLangPackSwitch() const { // #TODO multi we offer only if we were upgraded from an old authed app. return activeAccount().sessionExists(); } diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index 1f3c66531..705e6c4f8 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -169,7 +169,7 @@ public: [[nodiscard]] Lang::CloudManager *langCloudManager() { return _langCloudManager.get(); } - [[nodiscard]] bool offerLangPackSwitch() const; + [[nodiscard]] bool offerLegacyLangPackSwitch() const; [[nodiscard]] bool canApplyLangPackWithoutRestart() const; [[nodiscard]] ChatHelpers::EmojiKeywords &emojiKeywords() { return *_emojiKeywords; diff --git a/Telegram/SourceFiles/core/update_checker.cpp b/Telegram/SourceFiles/core/update_checker.cpp index 295a3ebb5..6712c83ed 100644 --- a/Telegram/SourceFiles/core/update_checker.cpp +++ b/Telegram/SourceFiles/core/update_checker.cpp @@ -1590,7 +1590,7 @@ void UpdateApplication() { Window::SectionShow()); } else { window->showSpecialLayer( - Box<::Settings::LayerWidget>(), + Box<::Settings::LayerWidget>(&window->controller()), anim::type::normal); } window->showFromTray(); diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 7582c3668..779261f8b 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -381,6 +381,7 @@ void Widget::updateScrollUpPosition() { void Widget::setupConnectingWidget() { _connecting = std::make_unique( this, + &session().account(), Window::AdaptiveIsOneColumn()); } diff --git a/Telegram/SourceFiles/info/info_section_widget.cpp b/Telegram/SourceFiles/info/info_section_widget.cpp index cc0141ddf..08c59fc5a 100644 --- a/Telegram/SourceFiles/info/info_section_widget.cpp +++ b/Telegram/SourceFiles/info/info_section_widget.cpp @@ -8,6 +8,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_section_widget.h" #include "window/window_connecting_widget.h" +#include "window/window_session_controller.h" +#include "main/main_session.h" #include "info/info_content_widget.h" #include "info/info_wrap_widget.h" #include "info/info_layer_widget.h" @@ -48,6 +50,7 @@ void SectionWidget::init() { _connecting = std::make_unique( _content.data(), + &controller()->session().account(), Window::AdaptiveIsOneColumn()); _content->contentChanged( diff --git a/Telegram/SourceFiles/intro/intro_widget.cpp b/Telegram/SourceFiles/intro/intro_widget.cpp index bb8a0e67c..147efa6fb 100644 --- a/Telegram/SourceFiles/intro/intro_widget.cpp +++ b/Telegram/SourceFiles/intro/intro_widget.cpp @@ -56,6 +56,7 @@ Widget::Widget(QWidget *parent, not_null account) object_ptr(this, nullptr, st::introNextButton)) , _connecting(std::make_unique( this, + account, rpl::single(true))) { appendStep(new StartWidget(this, _account, getData())); fixOrder(); diff --git a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp index b332da7e2..bbfb74155 100644 --- a/Telegram/SourceFiles/lang/lang_cloud_manager.cpp +++ b/Telegram/SourceFiles/lang/lang_cloud_manager.cpp @@ -158,7 +158,7 @@ Language ParseLanguage(const MTPLangPackLanguage &data) { CloudManager::CloudManager(Instance &langpack) : _langpack(langpack) { - Core::App().activeAccount().mtpValue( + Core::App().activeAccount().mtpValue( // #TODO multi activeAccountValue ) | rpl::start_with_next([=](MTP::Instance *instance) { if (instance) { _api.emplace(instance); diff --git a/Telegram/SourceFiles/main/main_account.cpp b/Telegram/SourceFiles/main/main_account.cpp index 6f3002d84..460995c67 100644 --- a/Telegram/SourceFiles/main/main_account.cpp +++ b/Telegram/SourceFiles/main/main_account.cpp @@ -182,19 +182,17 @@ rpl::producer<> Account::mtpNewSessionCreated() const { return _mtpNewSessionCreated.events(); } -void Account::setMtpMainDcId(MTP::DcId mainDcId) { +void Account::setLegacyMtpMainDcId(MTP::DcId mainDcId) { Expects(!_mtp); _mtpConfig.mainDcId = mainDcId; } -void Account::setMtpKey(MTP::DcId dcId, const MTP::AuthKey::Data &keyData) { +void Account::setLegacyMtpKey(std::shared_ptr key) { Expects(!_mtp); + Expects(key != nullptr); - _mtpConfig.keys.push_back(std::make_shared( - MTP::AuthKey::Type::ReadFromFile, - dcId, - keyData)); + _mtpConfig.keys.push_back(std::move(key)); } QByteArray Account::serializeMtpAuthorization() const { diff --git a/Telegram/SourceFiles/main/main_account.h b/Telegram/SourceFiles/main/main_account.h index 2781f43aa..f46065e25 100644 --- a/Telegram/SourceFiles/main/main_account.h +++ b/Telegram/SourceFiles/main/main_account.h @@ -59,8 +59,8 @@ public: [[nodiscard]] rpl::producer mtpChanges() const; // Set from legacy storage. - void setMtpMainDcId(MTP::DcId mainDcId); - void setMtpKey(MTP::DcId dcId, const MTP::AuthKey::Data &keyData); + void setLegacyMtpMainDcId(MTP::DcId mainDcId); + void setLegacyMtpKey(std::shared_ptr key); void setSessionUserId(UserId userId); void setSessionFromStorage( std::unique_ptr data, diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index c41bb7383..e41cd4d47 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -529,6 +529,7 @@ void MainWidget::setupConnectingWidget() { using namespace rpl::mappers; _connecting = std::make_unique( this, + &session().account(), Window::AdaptiveIsOneColumn() | rpl::map(!_1)); } diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index ac55e20f7..c64cca946 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -305,10 +305,12 @@ void MainWindow::showSettings() { return; } - if (const auto controller = sessionController()) { - controller->showSettings(); + if (const auto session = sessionController()) { + session->showSettings(); } else { - showSpecialLayer(Box(), anim::type::normal); + showSpecialLayer( + Box(&controller()), + anim::type::normal); } } diff --git a/Telegram/SourceFiles/media/player/media_player_instance.cpp b/Telegram/SourceFiles/media/player/media_player_instance.cpp index ba21f031b..a5263b00a 100644 --- a/Telegram/SourceFiles/media/player/media_player_instance.cpp +++ b/Telegram/SourceFiles/media/player/media_player_instance.cpp @@ -114,7 +114,7 @@ Instance::Instance() }); // While we have one Media::Player::Instance for all sessions we have to do this. - Core::App().activeAccount().sessionValue( + Core::App().activeAccount().sessionValue( // #TODO multi activeSessionValue ) | rpl::start_with_next([=](Main::Session *session) { if (session) { subscribe(session->calls().currentCallChanged(), [=](Calls::Call *call) { diff --git a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp index 6923e7098..6271f0cb3 100644 --- a/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp +++ b/Telegram/SourceFiles/media/view/media_view_overlay_widget.cpp @@ -304,6 +304,7 @@ OverlayWidget::OverlayWidget() ? Global::VideoVolume() : Global::kDefaultVolume; + // #TODO multi activeSessionValue change icon on show? setWindowIcon(Window::CreateIcon(&Core::App().activeAccount())); setWindowTitle(qsl("Media viewer")); @@ -320,7 +321,7 @@ OverlayWidget::OverlayWidget() connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(onScreenResized(int))); // While we have one mediaview for all sessions we have to do this. - Core::App().activeAccount().sessionValue( + Core::App().activeAccount().sessionValue( // #TODO multi activeSessionValue ) | rpl::start_with_next([=](Main::Session *session) { if (session) { subscribe(session->downloaderTaskFinished(), [=] { diff --git a/Telegram/SourceFiles/mtproto/facade.cpp b/Telegram/SourceFiles/mtproto/facade.cpp index a776a958e..011999252 100644 --- a/Telegram/SourceFiles/mtproto/facade.cpp +++ b/Telegram/SourceFiles/mtproto/facade.cpp @@ -39,7 +39,7 @@ void unpause() { } // namespace details Instance *MainInstance() { - return Core::IsAppLaunched() + return Core::IsAppLaunched() // #TODO multi ? Core::App().activeAccount().mtp() : nullptr; } diff --git a/Telegram/SourceFiles/mtproto/mtp_instance.cpp b/Telegram/SourceFiles/mtproto/mtp_instance.cpp index 1e0c37976..3aec7f4f8 100644 --- a/Telegram/SourceFiles/mtproto/mtp_instance.cpp +++ b/Telegram/SourceFiles/mtproto/mtp_instance.cpp @@ -854,7 +854,7 @@ void Instance::Private::configLoadDone(const MTPConfig &result) { data.vlang_pack_version().value_or_empty(), data.vbase_lang_pack_version().value_or_empty()); - Core::App().activeAccount().configUpdated(); + Core::App().activeAccount().configUpdated(); // #TODO multi if (const auto prefix = data.vautoupdate_url_prefix()) { Local::writeAutoupdatePrefix(qs(*prefix)); diff --git a/Telegram/SourceFiles/settings/settings_advanced.cpp b/Telegram/SourceFiles/settings/settings_advanced.cpp index 0d3dabe9a..1872e164c 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.cpp +++ b/Telegram/SourceFiles/settings/settings_advanced.cpp @@ -48,7 +48,9 @@ bool HasConnectionType() { return false; } -void SetupConnectionType(not_null container) { +void SetupConnectionType( + not_null account, + not_null container) { if (!HasConnectionType()) { return; } @@ -74,8 +76,8 @@ void SetupConnectionType(not_null container) { Global::RefConnectionTypeChanged() )) | rpl::map(connectionType), st::settingsButton); - button->addClickHandler([] { - Ui::show(ProxiesBoxController::CreateOwningBox()); + button->addClickHandler([=] { + Ui::show(ProxiesBoxController::CreateOwningBox(account)); }); #endif // TDESKTOP_DISABLE_NETWORK_PROXY } @@ -563,7 +565,7 @@ void Advanced::setupContent(not_null controller) { addDivider(); AddSkip(content); AddSubsectionTitle(content, tr::lng_settings_network_proxy()); - SetupConnectionType(content); + SetupConnectionType(&controller->session().account(), content); AddSkip(content); } SetupDataStorage(controller, content); diff --git a/Telegram/SourceFiles/settings/settings_advanced.h b/Telegram/SourceFiles/settings/settings_advanced.h index 998f3700d..d40ad7e95 100644 --- a/Telegram/SourceFiles/settings/settings_advanced.h +++ b/Telegram/SourceFiles/settings/settings_advanced.h @@ -9,10 +9,16 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_common.h" +namespace Main { +class Account; +} // namespace Main + namespace Settings { bool HasConnectionType(); -void SetupConnectionType(not_null container); +void SetupConnectionType( + not_null account, + not_null container); bool HasUpdate(); void SetupUpdate(not_null container); bool HasTray(); diff --git a/Telegram/SourceFiles/settings/settings_intro.cpp b/Telegram/SourceFiles/settings/settings_intro.cpp index 276c998e0..c9b9bae01 100644 --- a/Telegram/SourceFiles/settings/settings_intro.cpp +++ b/Telegram/SourceFiles/settings/settings_intro.cpp @@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/scroll_area.h" #include "lang/lang_keys.h" #include "boxes/abstract_box.h" +#include "window/window_controller.h" #include "app.h" #include "styles/style_settings.h" #include "styles/style_layers.h" @@ -56,14 +57,16 @@ private: }; -object_ptr CreateIntroSettings(QWidget *parent) { +object_ptr CreateIntroSettings( + QWidget *parent, + not_null window) { auto result = object_ptr(parent); AddDivider(result); AddSkip(result); SetupLanguageButton(result, false); if (HasConnectionType()) { - SetupConnectionType(result); + SetupConnectionType(&window->account(), result); } AddSkip(result); if (HasUpdate()) { @@ -162,7 +165,9 @@ void TopBar::paintEvent(QPaintEvent *e) { class IntroWidget : public Ui::RpWidget { public: - IntroWidget(QWidget *parent); + IntroWidget( + QWidget *parent, + not_null window); void forceContentRepaint(); @@ -184,7 +189,7 @@ private: void updateControlsGeometry(); QRect contentGeometry() const; void setInnerWidget(object_ptr content); - void showContent(); + void showContent(not_null window); rpl::producer topShadowToggledValue() const; void createTopBar(); void applyAdditionalScroll(int additionalScroll); @@ -203,7 +208,9 @@ private: }; -IntroWidget::IntroWidget(QWidget *parent) +IntroWidget::IntroWidget( + QWidget *parent, + not_null window) : RpWidget(parent) , _wrap(this) , _scroll(Ui::CreateChild(_wrap.data(), st::infoScroll)) @@ -221,7 +228,7 @@ IntroWidget::IntroWidget(QWidget *parent) }, lifetime()); createTopBar(); - showContent(); + showContent(window); _topShadow->toggleOn( topShadowToggledValue( ) | rpl::filter([](bool shown) { @@ -316,8 +323,8 @@ rpl::producer IntroWidget::topShadowToggledValue() const { ) | rpl::map((_1 > 0) || (_2 > 0)); } -void IntroWidget::showContent() { - setInnerWidget(CreateIntroSettings(_scroll)); +void IntroWidget::showContent(not_null window) { + setInnerWidget(CreateIntroSettings(_scroll, window)); _additionalScroll = 0; updateControlsGeometry(); @@ -393,8 +400,8 @@ rpl::producer IntroWidget::scrollTillBottomChanges() const { IntroWidget::~IntroWidget() = default; -LayerWidget::LayerWidget(QWidget*) -: _content(this) { +LayerWidget::LayerWidget(QWidget*, not_null window) +: _content(this, window) { setupHeightConsumers(); } diff --git a/Telegram/SourceFiles/settings/settings_intro.h b/Telegram/SourceFiles/settings/settings_intro.h index 1213be7a3..ec14f520d 100644 --- a/Telegram/SourceFiles/settings/settings_intro.h +++ b/Telegram/SourceFiles/settings/settings_intro.h @@ -17,13 +17,17 @@ template class FadeWrap; } // namespace Ui +namespace Window { +class Controller; +} // namespace Window + namespace Settings { class IntroWidget; class LayerWidget : public Ui::LayerWidget { public: - LayerWidget(QWidget*); + LayerWidget(QWidget*, not_null window); void showFinished() override; void parentResized() override; diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp index 98bd475e3..bec9b88b7 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.cpp @@ -10,7 +10,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "storage/details/storage_file_utilities.h" #include "storage/cache/storage_cache_database.h" #include "core/application.h" -#include "main/main_account.h" #include "storage/serialize_common.h" #include "ui/effects/animation_value.h" #include "ui/widgets/input_fields.h" @@ -134,8 +133,8 @@ bool ReadSetting( if (!CheckStreamStatus(stream)) return false; DEBUG_LOG(("MTP Info: user found, dc %1, uid %2").arg(dcId).arg(userId)); - Core::App().activeAccount().setMtpMainDcId(dcId); - Core::App().activeAccount().setSessionUserId(userId); + context.mtpLegacyMainDcId = dcId; + context.mtpLegacyUserId = userId; } break; case dbiKey: { @@ -144,7 +143,10 @@ bool ReadSetting( auto key = Serialize::read(stream); if (!CheckStreamStatus(stream)) return false; - Core::App().activeAccount().setMtpKey(dcId, key); + context.mtpLegacyKeys.push_back(std::make_shared( + MTP::AuthKey::Type::ReadFromFile, + dcId, + key)); } break; case dbiMtpAuthorization: { @@ -152,7 +154,7 @@ bool ReadSetting( stream >> serialized; if (!CheckStreamStatus(stream)) return false; - Core::App().activeAccount().setMtpAuthorization(serialized); + context.mtpAuthorization = serialized; } break; case dbiAutoStart: { diff --git a/Telegram/SourceFiles/storage/details/storage_settings_scheme.h b/Telegram/SourceFiles/storage/details/storage_settings_scheme.h index 41da5f380..da5b5caec 100644 --- a/Telegram/SourceFiles/storage/details/storage_settings_scheme.h +++ b/Telegram/SourceFiles/storage/details/storage_settings_scheme.h @@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_settings.h" #include "storage/storage_account.h" +namespace MTP { +class AuthKey; +} // namespace MTP + namespace Storage { namespace details { @@ -42,6 +46,11 @@ struct ReadSettingsContext { FileKey languagesKey = 0; QByteArray callSettings; + + QByteArray mtpAuthorization; + std::vector> mtpLegacyKeys; + qint32 mtpLegacyMainDcId = 0; + qint32 mtpLegacyUserId = 0; }; [[nodiscard]] bool ReadSetting( diff --git a/Telegram/SourceFiles/storage/storage_account.cpp b/Telegram/SourceFiles/storage/storage_account.cpp index 84295ff50..bb1ee9ed7 100644 --- a/Telegram/SourceFiles/storage/storage_account.cpp +++ b/Telegram/SourceFiles/storage/storage_account.cpp @@ -906,7 +906,20 @@ std::unique_ptr Account::applyReadContext( _cacheBigFileTotalSizeLimit = context.cacheBigFileTotalSizeLimit; _cacheBigFileTotalTimeLimit = context.cacheBigFileTotalTimeLimit; - deserializeCallSettings(context.callSettings); + if (!context.callSettings.isEmpty()) { + deserializeCallSettings(context.callSettings); + } + if (!context.mtpAuthorization.isEmpty()) { + _owner->setMtpAuthorization(context.mtpAuthorization); + } else { + for (auto &key : context.mtpLegacyKeys) { + _owner->setLegacyMtpKey(std::move(key)); + } + if (context.mtpLegacyMainDcId) { + _owner->setLegacyMtpMainDcId(context.mtpLegacyMainDcId); + _owner->setSessionUserId(context.mtpLegacyUserId); + } + } return std::move(context.sessionSettingsStorage); } @@ -918,7 +931,7 @@ void Account::writeMtpData() { return; } - auto mtpAuthorizationSerialized = Core::App().activeAccount().serializeMtpAuthorization(); + auto mtpAuthorizationSerialized = _owner->serializeMtpAuthorization(); quint32 size = sizeof(quint32) + Serialize::bytearraySize(mtpAuthorizationSerialized); diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index e8ee53890..10addd66e 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -547,7 +547,7 @@ void ChatBackground::start() { set(Data::ThemeWallPaper()); } - Core::App().activeAccount().sessionValue( + Core::App().activeAccount().sessionValue( // #TODO multi activeSessionValue ) | rpl::filter([=](Main::Session *session) { return session != _session; }) | rpl::start_with_next([=](Main::Session *session) { diff --git a/Telegram/SourceFiles/window/window_connecting_widget.cpp b/Telegram/SourceFiles/window/window_connecting_widget.cpp index 5bf13d774..83813f435 100644 --- a/Telegram/SourceFiles/window/window_connecting_widget.cpp +++ b/Telegram/SourceFiles/window/window_connecting_widget.cpp @@ -74,7 +74,10 @@ void Progress::animationStep() { class ConnectionState::Widget : public Ui::AbstractButton { public: - Widget(QWidget *parent, const Layout &layout); + Widget( + QWidget *parent, + not_null account, + const Layout &layout); void refreshRetryLink(bool hasRetry); void setLayout(const Layout &layout); @@ -201,8 +204,10 @@ bool ConnectionState::State::operator==(const State &other) const { ConnectionState::ConnectionState( not_null parent, + not_null account, rpl::producer shown) -: _parent(parent) +: _account(account) +, _parent(parent) , _refreshTimer([=] { refreshState(); }) , _currentLayout(computeLayout(_state)) { rpl::combine( @@ -232,7 +237,7 @@ ConnectionState::ConnectionState( } void ConnectionState::createWidget() { - _widget = base::make_unique_q(_parent, _currentLayout); + _widget = base::make_unique_q(_parent, _account, _currentLayout); _widget->setVisible(!_forceHidden); updateWidth(); @@ -469,14 +474,17 @@ void ConnectionState::updateWidth() { refreshProgressVisibility(); } -ConnectionState::Widget::Widget(QWidget *parent, const Layout &layout) +ConnectionState::Widget::Widget( + QWidget *parent, + not_null account, + const Layout &layout) : AbstractButton(parent) , _currentLayout(layout) { _proxyIcon = Ui::CreateChild(this); _progress = Ui::CreateChild(this); addClickHandler([=] { - Ui::show(ProxiesBoxController::CreateOwningBox()); + Ui::show(ProxiesBoxController::CreateOwningBox(account)); }); } diff --git a/Telegram/SourceFiles/window/window_connecting_widget.h b/Telegram/SourceFiles/window/window_connecting_widget.h index 98ffbeba8..e714cc61f 100644 --- a/Telegram/SourceFiles/window/window_connecting_widget.h +++ b/Telegram/SourceFiles/window/window_connecting_widget.h @@ -15,12 +15,17 @@ namespace Ui { class RpWidget; } // namespace Ui +namespace Main { +class Account; +} // namespace Main + namespace Window { class ConnectionState : private base::Subscriber { public: ConnectionState( not_null parent, + not_null account, rpl::producer shown); void raise(); @@ -71,6 +76,7 @@ private: void updateVisibility(); void refreshProgressVisibility(); + const not_null _account; not_null _parent; base::unique_qptr _widget; bool _forceHidden = false;