Wrap AuthSession in a new Main::Account object.

This commit is contained in:
John Preston 2019-04-30 15:12:30 +04:00
parent 8c67a4b991
commit bd2e1ceb02
5 changed files with 86 additions and 2 deletions

View File

@ -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*> launcher)
, _private(std::make_unique<Private>())
, _databases(std::make_unique<Storage::Databases>())
, _animationsManager(std::make_unique<Ui::Animations::Manager>())
, _account(std::make_unique<Main::Account>(cDataFile()))
, _langpack(std::make_unique<Lang::Instance>())
, _emojiKeywords(std::make_unique<ChatHelpers::EmojiKeywords>())
, _audio(std::make_unique<Media::Audio::Instance>())
@ -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();

View File

@ -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<Storage::Databases> _databases;
const std::unique_ptr<Ui::Animations::Manager> _animationsManager;
const std::unique_ptr<Main::Account> _account;
std::unique_ptr<MainWindow> _window;
std::unique_ptr<Media::View::OverlayWidget> _mediaView;
const std::unique_ptr<Lang::Instance> _langpack;

View File

@ -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<AuthSession*> 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

View File

@ -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<AuthSession*> sessionValue() const;
[[nodiscard]] MTP::Instance *mtp();
private:
};
} // namespace Main

View File

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