Access _authSession through activeAccount().
This commit is contained in:
		
							parent
							
								
									bd2e1ceb02
								
							
						
					
					
						commit
						94c4ea6174
					
				
					 10 changed files with 93 additions and 54 deletions
				
			
		| 
						 | 
					@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "apiwrap.h"
 | 
					#include "apiwrap.h"
 | 
				
			||||||
#include "core/application.h"
 | 
					#include "core/application.h"
 | 
				
			||||||
#include "core/changelogs.h"
 | 
					#include "core/changelogs.h"
 | 
				
			||||||
 | 
					#include "main/main_account.h"
 | 
				
			||||||
#include "storage/file_download.h"
 | 
					#include "storage/file_download.h"
 | 
				
			||||||
#include "storage/file_upload.h"
 | 
					#include "storage/file_upload.h"
 | 
				
			||||||
#include "storage/localstorage.h"
 | 
					#include "storage/localstorage.h"
 | 
				
			||||||
| 
						 | 
					@ -408,13 +409,14 @@ rpl::producer<bool> AuthSessionSettings::notifyAboutPinnedChanges() const {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AuthSession &Auth() {
 | 
					AuthSession &Auth() {
 | 
				
			||||||
	const auto result = Core::App().authSession();
 | 
						return Core::App().activeAccount().session();
 | 
				
			||||||
	Assert(result != nullptr);
 | 
					 | 
				
			||||||
	return *result;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
AuthSession::AuthSession(const MTPUser &user)
 | 
					AuthSession::AuthSession(
 | 
				
			||||||
: _autoLockTimer([this] { checkAutoLock(); })
 | 
						not_null<Main::Account*> account,
 | 
				
			||||||
 | 
						const MTPUser &user)
 | 
				
			||||||
 | 
					: _account(account)
 | 
				
			||||||
 | 
					, _autoLockTimer([=] { checkAutoLock(); })
 | 
				
			||||||
, _api(std::make_unique<ApiWrap>(this))
 | 
					, _api(std::make_unique<ApiWrap>(this))
 | 
				
			||||||
, _calls(std::make_unique<Calls::Instance>())
 | 
					, _calls(std::make_unique<Calls::Instance>())
 | 
				
			||||||
, _downloader(std::make_unique<Storage::Downloader>(_api.get()))
 | 
					, _downloader(std::make_unique<Storage::Downloader>(_api.get()))
 | 
				
			||||||
| 
						 | 
					@ -425,7 +427,6 @@ AuthSession::AuthSession(const MTPUser &user)
 | 
				
			||||||
, _user(_data->processUser(user))
 | 
					, _user(_data->processUser(user))
 | 
				
			||||||
, _changelogs(Core::Changelogs::Create(this))
 | 
					, _changelogs(Core::Changelogs::Create(this))
 | 
				
			||||||
, _supportHelper(Support::Helper::Create(this)) {
 | 
					, _supportHelper(Support::Helper::Create(this)) {
 | 
				
			||||||
 | 
					 | 
				
			||||||
	_saveDataTimer.setCallback([=] {
 | 
						_saveDataTimer.setCallback([=] {
 | 
				
			||||||
		Local::writeUserSettings();
 | 
							Local::writeUserSettings();
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
| 
						 | 
					@ -465,8 +466,18 @@ AuthSession::AuthSession(const MTPUser &user)
 | 
				
			||||||
	Window::Theme::Background()->start();
 | 
						Window::Theme::Background()->start();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					AuthSession::~AuthSession() {
 | 
				
			||||||
 | 
						ClickHandler::clearActive();
 | 
				
			||||||
 | 
						ClickHandler::unpressed();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Main::Account &AuthSession::account() const {
 | 
				
			||||||
 | 
						return *_account;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool AuthSession::Exists() {
 | 
					bool AuthSession::Exists() {
 | 
				
			||||||
	return Core::IsAppLaunched() && (Core::App().authSession() != nullptr);
 | 
						return Core::IsAppLaunched()
 | 
				
			||||||
 | 
							&& Core::App().activeAccount().sessionExists();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
base::Observable<void> &AuthSession::downloaderTaskFinished() {
 | 
					base::Observable<void> &AuthSession::downloaderTaskFinished() {
 | 
				
			||||||
| 
						 | 
					@ -566,8 +577,3 @@ Support::Helper &AuthSession::supportHelper() const {
 | 
				
			||||||
Support::Templates& AuthSession::supportTemplates() const {
 | 
					Support::Templates& AuthSession::supportTemplates() const {
 | 
				
			||||||
	return supportHelper().templates();
 | 
						return supportHelper().templates();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
AuthSession::~AuthSession() {
 | 
					 | 
				
			||||||
	ClickHandler::clearActive();
 | 
					 | 
				
			||||||
	ClickHandler::unpressed();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,6 +16,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
class ApiWrap;
 | 
					class ApiWrap;
 | 
				
			||||||
enum class SendFilesWay;
 | 
					enum class SendFilesWay;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace Main {
 | 
				
			||||||
 | 
					class Account;
 | 
				
			||||||
 | 
					} // namespace Main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
namespace Ui {
 | 
					namespace Ui {
 | 
				
			||||||
enum class InputSubmitSettings;
 | 
					enum class InputSubmitSettings;
 | 
				
			||||||
} // namespace Ui
 | 
					} // namespace Ui
 | 
				
			||||||
| 
						 | 
					@ -277,13 +281,16 @@ class AuthSession final
 | 
				
			||||||
	: public base::has_weak_ptr
 | 
						: public base::has_weak_ptr
 | 
				
			||||||
	, private base::Subscriber {
 | 
						, private base::Subscriber {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	AuthSession(const MTPUser &user);
 | 
						AuthSession(not_null<Main::Account*> account, const MTPUser &user);
 | 
				
			||||||
 | 
						~AuthSession();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	AuthSession(const AuthSession &other) = delete;
 | 
						AuthSession(const AuthSession &other) = delete;
 | 
				
			||||||
	AuthSession &operator=(const AuthSession &other) = delete;
 | 
						AuthSession &operator=(const AuthSession &other) = delete;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	static bool Exists();
 | 
						static bool Exists();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Main::Account &account() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	UserId userId() const;
 | 
						UserId userId() const;
 | 
				
			||||||
	PeerId userPeerId() const;
 | 
						PeerId userPeerId() const;
 | 
				
			||||||
	not_null<UserData*> user() const {
 | 
						not_null<UserData*> user() const {
 | 
				
			||||||
| 
						 | 
					@ -340,11 +347,11 @@ public:
 | 
				
			||||||
	Support::Helper &supportHelper() const;
 | 
						Support::Helper &supportHelper() const;
 | 
				
			||||||
	Support::Templates &supportTemplates() const;
 | 
						Support::Templates &supportTemplates() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	~AuthSession();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
	static constexpr auto kDefaultSaveDelay = crl::time(1000);
 | 
						static constexpr auto kDefaultSaveDelay = crl::time(1000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						const not_null<Main::Account*> _account;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	AuthSessionSettings _settings;
 | 
						AuthSessionSettings _settings;
 | 
				
			||||||
	base::Timer _saveDataTimer;
 | 
						base::Timer _saveDataTimer;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
				
			||||||
#include "core/application.h"
 | 
					#include "core/application.h"
 | 
				
			||||||
#include "platform/platform_info.h"
 | 
					#include "platform/platform_info.h"
 | 
				
			||||||
#include "ui/emoji_config.h"
 | 
					#include "ui/emoji_config.h"
 | 
				
			||||||
 | 
					#include "main/main_account.h"
 | 
				
			||||||
#include "auth_session.h"
 | 
					#include "auth_session.h"
 | 
				
			||||||
#include "apiwrap.h"
 | 
					#include "apiwrap.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -486,12 +487,9 @@ void EmojiKeywords::langPackRefreshed() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void EmojiKeywords::handleAuthSessionChanges() {
 | 
					void EmojiKeywords::handleAuthSessionChanges() {
 | 
				
			||||||
	rpl::single(
 | 
						Core::App().activeAccount().sessionValue(
 | 
				
			||||||
		rpl::empty_value()
 | 
						) | rpl::map([](AuthSession *session) {
 | 
				
			||||||
	) | rpl::then(base::ObservableViewer(
 | 
							return session ? &session->api() : nullptr;
 | 
				
			||||||
		Core::App().authSessionChanged()
 | 
					 | 
				
			||||||
	)) | rpl::map([] {
 | 
					 | 
				
			||||||
		return AuthSession::Exists() ? &Auth().api() : nullptr;
 | 
					 | 
				
			||||||
	}) | rpl::start_with_next([=](ApiWrap *api) {
 | 
						}) | rpl::start_with_next([=](ApiWrap *api) {
 | 
				
			||||||
		apiChanged(api);
 | 
							apiChanged(api);
 | 
				
			||||||
	}, _lifetime);
 | 
						}, _lifetime);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -397,7 +397,9 @@ QByteArray Application::serializeMtpAuthorization() const {
 | 
				
			||||||
			QDataStream stream(&result, QIODevice::WriteOnly);
 | 
								QDataStream stream(&result, QIODevice::WriteOnly);
 | 
				
			||||||
			stream.setVersion(QDataStream::Qt_5_1);
 | 
								stream.setVersion(QDataStream::Qt_5_1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			auto currentUserId = _authSession ? _authSession->userId() : 0;
 | 
								auto currentUserId = activeAccount().sessionExists()
 | 
				
			||||||
 | 
									? activeAccount().session().userId()
 | 
				
			||||||
 | 
									: 0;
 | 
				
			||||||
			stream << qint32(currentUserId) << qint32(mainDcId);
 | 
								stream << qint32(currentUserId) << qint32(mainDcId);
 | 
				
			||||||
			writeKeys(stream, keys);
 | 
								writeKeys(stream, keys);
 | 
				
			||||||
			writeKeys(stream, keysToDestroy);
 | 
								writeKeys(stream, keysToDestroy);
 | 
				
			||||||
| 
						 | 
					@ -417,7 +419,7 @@ QByteArray Application::serializeMtpAuthorization() const {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Application::setAuthSessionUserId(UserId userId) {
 | 
					void Application::setAuthSessionUserId(UserId userId) {
 | 
				
			||||||
	Expects(!authSession());
 | 
						Expects(!activeAccount().sessionExists());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_private->authSessionUserId = userId;
 | 
						_private->authSessionUserId = userId;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -426,7 +428,7 @@ void Application::setAuthSessionFromStorage(
 | 
				
			||||||
		std::unique_ptr<AuthSessionSettings> data,
 | 
							std::unique_ptr<AuthSessionSettings> data,
 | 
				
			||||||
		QByteArray &&selfSerialized,
 | 
							QByteArray &&selfSerialized,
 | 
				
			||||||
		int32 selfStreamVersion) {
 | 
							int32 selfStreamVersion) {
 | 
				
			||||||
	Expects(!authSession());
 | 
						Expects(!activeAccount().sessionExists());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	DEBUG_LOG(("authSessionUserSerialized set: %1"
 | 
						DEBUG_LOG(("authSessionUserSerialized set: %1"
 | 
				
			||||||
		).arg(selfSerialized.size()));
 | 
							).arg(selfSerialized.size()));
 | 
				
			||||||
| 
						 | 
					@ -441,8 +443,8 @@ AuthSessionSettings *Application::getAuthSessionSettings() {
 | 
				
			||||||
		return _private->storedAuthSession
 | 
							return _private->storedAuthSession
 | 
				
			||||||
			? _private->storedAuthSession.get()
 | 
								? _private->storedAuthSession.get()
 | 
				
			||||||
			: nullptr;
 | 
								: nullptr;
 | 
				
			||||||
	} else if (_authSession) {
 | 
						} else if (activeAccount().sessionExists()) {
 | 
				
			||||||
		return &_authSession->settings();
 | 
							return &activeAccount().session().settings();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return nullptr;
 | 
						return nullptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -542,8 +544,8 @@ void Application::startMtp() {
 | 
				
			||||||
			base::take(_private->authSessionUserStreamVersion));
 | 
								base::take(_private->authSessionUserStreamVersion));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (_private->storedAuthSession) {
 | 
						if (_private->storedAuthSession) {
 | 
				
			||||||
		if (_authSession) {
 | 
							if (activeAccount().sessionExists()) {
 | 
				
			||||||
			_authSession->moveSettingsFrom(
 | 
								activeAccount().session().moveSettingsFrom(
 | 
				
			||||||
				std::move(*_private->storedAuthSession));
 | 
									std::move(*_private->storedAuthSession));
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		_private->storedAuthSession.reset();
 | 
							_private->storedAuthSession.reset();
 | 
				
			||||||
| 
						 | 
					@ -556,7 +558,7 @@ void Application::startMtp() {
 | 
				
			||||||
		UpdateChecker().setMtproto(mtp());
 | 
							UpdateChecker().setMtproto(mtp());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (_authSession) {
 | 
						if (activeAccount().sessionExists()) {
 | 
				
			||||||
		// Skip all pending self updates so that we won't Local::writeSelf.
 | 
							// Skip all pending self updates so that we won't Local::writeSelf.
 | 
				
			||||||
		Notify::peerUpdatedSendDelayed();
 | 
							Notify::peerUpdatedSendDelayed();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					@ -644,11 +646,14 @@ void Application::startLocalStorage() {
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
	subscribe(authSessionChanged(), [=] {
 | 
						activeAccount().sessionChanges(
 | 
				
			||||||
		InvokeQueued(this, [=] {
 | 
						) | rpl::start_with_next([=] {
 | 
				
			||||||
			const auto phone = AuthSession::Exists()
 | 
							crl::on_main(this, [=] {
 | 
				
			||||||
				? Auth().user()->phone()
 | 
								const auto phone = activeAccount().sessionExists()
 | 
				
			||||||
 | 
										? activeAccount().session().user()->phone()
 | 
				
			||||||
					: QString();
 | 
										: QString();
 | 
				
			||||||
 | 
								const auto support = activeAccount().sessionExists()
 | 
				
			||||||
 | 
									&& activeAccount().session().supportMode();
 | 
				
			||||||
			if (cLoggedPhoneNumber() != phone) {
 | 
								if (cLoggedPhoneNumber() != phone) {
 | 
				
			||||||
				cSetLoggedPhoneNumber(phone);
 | 
									cSetLoggedPhoneNumber(phone);
 | 
				
			||||||
				if (_mtproto) {
 | 
									if (_mtproto) {
 | 
				
			||||||
| 
						 | 
					@ -660,10 +665,9 @@ void Application::startLocalStorage() {
 | 
				
			||||||
				_mtproto->requestConfig();
 | 
									_mtproto->requestConfig();
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			Platform::SetApplicationIcon(Window::CreateIcon());
 | 
								Platform::SetApplicationIcon(Window::CreateIcon());
 | 
				
			||||||
			Shortcuts::ToggleSupportShortcuts(
 | 
								Shortcuts::ToggleSupportShortcuts(support);
 | 
				
			||||||
				_authSession && _authSession->supportMode());
 | 
					 | 
				
			||||||
		});
 | 
					 | 
				
			||||||
		});
 | 
							});
 | 
				
			||||||
 | 
						}, _lifetime);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Application::forceLogOut(const TextWithEntities &explanation) {
 | 
					void Application::forceLogOut(const TextWithEntities &explanation) {
 | 
				
			||||||
| 
						 | 
					@ -768,7 +772,6 @@ void Application::writeInstallBetaVersionsSetting() {
 | 
				
			||||||
void Application::authSessionCreate(const MTPUser &user) {
 | 
					void Application::authSessionCreate(const MTPUser &user) {
 | 
				
			||||||
	Expects(_mtproto != nullptr);
 | 
						Expects(_mtproto != nullptr);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	_authSession = std::make_unique<AuthSession>(user);
 | 
					 | 
				
			||||||
	_mtproto->setUpdatesHandler(::rpcDone([](
 | 
						_mtproto->setUpdatesHandler(::rpcDone([](
 | 
				
			||||||
			const mtpPrime *from,
 | 
								const mtpPrime *from,
 | 
				
			||||||
			const mtpPrime *end) {
 | 
								const mtpPrime *end) {
 | 
				
			||||||
| 
						 | 
					@ -777,9 +780,13 @@ void Application::authSessionCreate(const MTPUser &user) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}));
 | 
						}));
 | 
				
			||||||
	_mtproto->setGlobalFailHandler(::rpcFail([=](const RPCError &error) {
 | 
						_mtproto->setGlobalFailHandler(::rpcFail([=](const RPCError &error) {
 | 
				
			||||||
		crl::on_main(_authSession.get(), [=] { logOut(); });
 | 
							if (activeAccount().sessionExists()) {
 | 
				
			||||||
 | 
								crl::on_main(&activeAccount().session(), [=] { logOut(); });
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		return true;
 | 
							return true;
 | 
				
			||||||
	}));
 | 
						}));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						_authSession = std::make_unique<AuthSession>(&activeAccount(), user);
 | 
				
			||||||
	authSessionChanged().notify(true);
 | 
						authSessionChanged().notify(true);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -787,7 +794,7 @@ void Application::authSessionDestroy() {
 | 
				
			||||||
	_private->storedAuthSession.reset();
 | 
						_private->storedAuthSession.reset();
 | 
				
			||||||
	_private->authSessionUserId = 0;
 | 
						_private->authSessionUserId = 0;
 | 
				
			||||||
	_private->authSessionUserSerialized = {};
 | 
						_private->authSessionUserSerialized = {};
 | 
				
			||||||
	if (_authSession) {
 | 
						if (activeAccount().sessionExists()) {
 | 
				
			||||||
		unlockTerms();
 | 
							unlockTerms();
 | 
				
			||||||
		_mtproto->clearGlobalHandlers();
 | 
							_mtproto->clearGlobalHandlers();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -797,16 +804,21 @@ void Application::authSessionDestroy() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		_authSession = nullptr;
 | 
							_authSession = nullptr;
 | 
				
			||||||
		authSessionChanged().notify(true);
 | 
							authSessionChanged().notify(true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Notify::unreadCounterUpdated();
 | 
							Notify::unreadCounterUpdated();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int Application::unreadBadge() const {
 | 
					int Application::unreadBadge() const {
 | 
				
			||||||
	return _authSession ? _authSession->data().unreadBadge() : 0;
 | 
						return activeAccount().sessionExists()
 | 
				
			||||||
 | 
							? activeAccount().session().data().unreadBadge()
 | 
				
			||||||
 | 
							: 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Application::unreadBadgeMuted() const {
 | 
					bool Application::unreadBadgeMuted() const {
 | 
				
			||||||
	return _authSession ? _authSession->data().unreadBadgeMuted() : false;
 | 
						return activeAccount().sessionExists()
 | 
				
			||||||
 | 
							? activeAccount().session().data().unreadBadgeMuted()
 | 
				
			||||||
 | 
							: false;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Application::setInternalLinkDomain(const QString &domain) const {
 | 
					void Application::setInternalLinkDomain(const QString &domain) const {
 | 
				
			||||||
| 
						 | 
					@ -1030,8 +1042,8 @@ void Application::loggedOut() {
 | 
				
			||||||
		window->tempDirDelete(Local::ClearManagerAll);
 | 
							window->tempDirDelete(Local::ClearManagerAll);
 | 
				
			||||||
		window->setupIntro();
 | 
							window->setupIntro();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (const auto session = authSession()) {
 | 
						if (activeAccount().sessionExists()) {
 | 
				
			||||||
		session->data().clearLocalStorage();
 | 
							activeAccount().session().data().clearLocalStorage();
 | 
				
			||||||
		authSessionDestroy();
 | 
							authSessionDestroy();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if (_mediaView) {
 | 
						if (_mediaView) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -153,7 +153,7 @@ public:
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Account component.
 | 
						// Account component.
 | 
				
			||||||
	Main::Account &activeAccount() {
 | 
						Main::Account &activeAccount() const {
 | 
				
			||||||
		return *_account;
 | 
							return *_account;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,6 +15,9 @@ namespace Main {
 | 
				
			||||||
Account::Account(const QString &dataName) {
 | 
					Account::Account(const QString &dataName) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Account::~Account() {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool Account::sessionExists() const {
 | 
					bool Account::sessionExists() const {
 | 
				
			||||||
	return Core::App().authSession() != nullptr;
 | 
						return Core::App().authSession() != nullptr;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -35,6 +38,14 @@ rpl::producer<AuthSession*> Account::sessionValue() const {
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					rpl::producer<AuthSession*> Account::sessionChanges() const {
 | 
				
			||||||
 | 
						return base::ObservableViewer(
 | 
				
			||||||
 | 
							Core::App().authSessionChanged()
 | 
				
			||||||
 | 
						) | rpl::map([] {
 | 
				
			||||||
 | 
							return Core::App().authSession();
 | 
				
			||||||
 | 
						});
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
MTP::Instance *Account::mtp() {
 | 
					MTP::Instance *Account::mtp() {
 | 
				
			||||||
	return MTP::MainInstance();
 | 
						return MTP::MainInstance();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -14,10 +14,15 @@ namespace Main {
 | 
				
			||||||
class Account final {
 | 
					class Account final {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	explicit Account(const QString &dataName);
 | 
						explicit Account(const QString &dataName);
 | 
				
			||||||
 | 
						~Account();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Account(const Account &other) = delete;
 | 
				
			||||||
 | 
						Account &operator=(const Account &other) = delete;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[[nodiscard]] bool sessionExists() const;
 | 
						[[nodiscard]] bool sessionExists() const;
 | 
				
			||||||
	[[nodiscard]] AuthSession &session();
 | 
						[[nodiscard]] AuthSession &session();
 | 
				
			||||||
	[[nodiscard]] rpl::producer<AuthSession*> sessionValue() const;
 | 
						[[nodiscard]] rpl::producer<AuthSession*> sessionValue() const;
 | 
				
			||||||
 | 
						[[nodiscard]] rpl::producer<AuthSession*> sessionChanges() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	[[nodiscard]] MTP::Instance *mtp();
 | 
						[[nodiscard]] MTP::Instance *mtp();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,8 +34,8 @@ constexpr auto kWaitingForAllGroupedDelay = crl::time(1000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
} // namespace
 | 
					} // namespace
 | 
				
			||||||
 | 
					
 | 
				
			||||||
System::System(AuthSession *session)
 | 
					System::System(not_null<AuthSession*> session)
 | 
				
			||||||
: _authSession(session)
 | 
					: _session(session)
 | 
				
			||||||
, _waitTimer([=] { showNext(); })
 | 
					, _waitTimer([=] { showNext(); })
 | 
				
			||||||
, _waitForAllGroupedTimer([=] { showGrouped(); }) {
 | 
					, _waitForAllGroupedTimer([=] { showGrouped(); }) {
 | 
				
			||||||
	createManager();
 | 
						createManager();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,7 +55,7 @@ class Manager;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class System final : private base::Subscriber {
 | 
					class System final : private base::Subscriber {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	System(AuthSession *session);
 | 
						explicit System(not_null<AuthSession*> session);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	void createManager();
 | 
						void createManager();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -71,8 +71,8 @@ public:
 | 
				
			||||||
		return _settingsChanged;
 | 
							return _settingsChanged;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	AuthSession *authSession() {
 | 
						AuthSession &session() const {
 | 
				
			||||||
		return _authSession;
 | 
							return *_session;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	~System();
 | 
						~System();
 | 
				
			||||||
| 
						 | 
					@ -82,7 +82,7 @@ private:
 | 
				
			||||||
	void showGrouped();
 | 
						void showGrouped();
 | 
				
			||||||
	void ensureSoundCreated();
 | 
						void ensureSoundCreated();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	AuthSession *_authSession = nullptr;
 | 
						not_null<AuthSession*> _session;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	QMap<History*, QMap<MsgId, crl::time>> _whenMaps;
 | 
						QMap<History*, QMap<MsgId, crl::time>> _whenMaps;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,8 +55,8 @@ std::unique_ptr<Manager> Create(System *system) {
 | 
				
			||||||
Manager::Manager(System *system)
 | 
					Manager::Manager(System *system)
 | 
				
			||||||
: Notifications::Manager(system)
 | 
					: Notifications::Manager(system)
 | 
				
			||||||
, _inputCheckTimer([=] { checkLastInput(); }) {
 | 
					, _inputCheckTimer([=] { checkLastInput(); }) {
 | 
				
			||||||
	subscribe(system->authSession()->downloader().taskFinished(), [this] {
 | 
						subscribe(system->session().downloader().taskFinished(), [this] {
 | 
				
			||||||
		for_const (auto ¬ification, _notifications) {
 | 
							for (const auto ¬ification : _notifications) {
 | 
				
			||||||
			notification->updatePeerPhoto();
 | 
								notification->updatePeerPhoto();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue