From bd2e1ceb02ae5182362b3156f5b0cfa2ea586b47 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 30 Apr 2019 15:12:30 +0400 Subject: [PATCH] Wrap AuthSession in a new Main::Account object. --- Telegram/SourceFiles/core/application.cpp | 4 ++- Telegram/SourceFiles/core/application.h | 12 ++++++- Telegram/SourceFiles/main/main_account.cpp | 42 ++++++++++++++++++++++ Telegram/SourceFiles/main/main_account.h | 28 +++++++++++++++ Telegram/gyp/telegram_sources.txt | 2 ++ 5 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 Telegram/SourceFiles/main/main_account.cpp create mode 100644 Telegram/SourceFiles/main/main_account.h diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 286023f36f..46d1df5040 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -34,6 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "observer_peer.h" #include "storage/storage_databases.h" #include "mainwidget.h" +#include "main/main_account.h" #include "media/view/media_view_overlay_widget.h" #include "mtproto/dc_options.h" #include "mtproto/mtp_instance.h" @@ -84,6 +85,7 @@ Application::Application(not_null launcher) , _private(std::make_unique()) , _databases(std::make_unique()) , _animationsManager(std::make_unique()) +, _account(std::make_unique(cDataFile())) , _langpack(std::make_unique()) , _emojiKeywords(std::make_unique()) , _audio(std::make_unique()) @@ -198,7 +200,7 @@ void Application::run() { DEBUG_LOG(("Application Info: local map read...")); startMtp(); DEBUG_LOG(("Application Info: MTP started...")); - if (AuthSession::Exists()) { + if (activeAccount().sessionExists()) { _window->setupMain(); } else { _window->setupIntro(); diff --git a/Telegram/SourceFiles/core/application.h b/Telegram/SourceFiles/core/application.h index 59090f3368..682f5db07b 100644 --- a/Telegram/SourceFiles/core/application.h +++ b/Telegram/SourceFiles/core/application.h @@ -34,6 +34,10 @@ namespace App { void quit(); } // namespace App +namespace Main { +class Account; +} // namespace Main + namespace Ui { namespace Animations { class Manager; @@ -143,11 +147,16 @@ public: void configUpdated(); [[nodiscard]] rpl::producer<> configUpdates() const; - // Databases + // Databases. Storage::Databases &databases() { return *_databases; } + // Account component. + Main::Account &activeAccount() { + return *_account; + } + // AuthSession component. AuthSession *authSession() { return _authSession.get(); @@ -269,6 +278,7 @@ private: const std::unique_ptr _databases; const std::unique_ptr _animationsManager; + const std::unique_ptr _account; std::unique_ptr _window; std::unique_ptr _mediaView; const std::unique_ptr _langpack; diff --git a/Telegram/SourceFiles/main/main_account.cpp b/Telegram/SourceFiles/main/main_account.cpp new file mode 100644 index 0000000000..1d67d98c95 --- /dev/null +++ b/Telegram/SourceFiles/main/main_account.cpp @@ -0,0 +1,42 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#include "main/main_account.h" + +#include "auth_session.h" +#include "core/application.h" + +namespace Main { + +Account::Account(const QString &dataName) { +} + +bool Account::sessionExists() const { + return Core::App().authSession() != nullptr; +} + +AuthSession &Account::session() { + Expects(sessionExists()); + + return *Core::App().authSession(); +} + +rpl::producer Account::sessionValue() const { + return rpl::single( + rpl::empty_value() + ) | rpl::then( + base::ObservableViewer(Core::App().authSessionChanged()) + ) | rpl::map([] { + return Core::App().authSession(); + }); +} + +MTP::Instance *Account::mtp() { + return MTP::MainInstance(); +} + +} // namespace Main diff --git a/Telegram/SourceFiles/main/main_account.h b/Telegram/SourceFiles/main/main_account.h new file mode 100644 index 0000000000..5ca6d47488 --- /dev/null +++ b/Telegram/SourceFiles/main/main_account.h @@ -0,0 +1,28 @@ +/* +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +*/ +#pragma once + +class AuthSession; + +namespace Main { + +class Account final { +public: + explicit Account(const QString &dataName); + + [[nodiscard]] bool sessionExists() const; + [[nodiscard]] AuthSession &session(); + [[nodiscard]] rpl::producer sessionValue() const; + + [[nodiscard]] MTP::Instance *mtp(); + +private: + +}; + +} // namespace Main diff --git a/Telegram/gyp/telegram_sources.txt b/Telegram/gyp/telegram_sources.txt index 3a7a6fcc46..929dac12db 100644 --- a/Telegram/gyp/telegram_sources.txt +++ b/Telegram/gyp/telegram_sources.txt @@ -429,6 +429,8 @@ <(src_loc)/lang/lang_tag.h <(src_loc)/lang/lang_translator.cpp <(src_loc)/lang/lang_translator.h +<(src_loc)/main/main_account.cpp +<(src_loc)/main/main_account.h <(src_loc)/media/audio/media_audio.cpp <(src_loc)/media/audio/media_audio.h <(src_loc)/media/audio/media_audio_capture.cpp