2019-04-30 11:12:30 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
|
2019-07-24 08:46:23 +00:00
|
|
|
#include "mtproto/auth_key.h"
|
|
|
|
#include "base/weak_ptr.h"
|
|
|
|
|
2019-04-30 11:12:30 +00:00
|
|
|
namespace Main {
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
class Session;
|
|
|
|
class Settings;
|
|
|
|
|
2019-07-24 08:46:23 +00:00
|
|
|
class Account final : public base::has_weak_ptr {
|
2019-04-30 11:12:30 +00:00
|
|
|
public:
|
|
|
|
explicit Account(const QString &dataName);
|
2019-06-05 20:41:51 +00:00
|
|
|
~Account();
|
|
|
|
|
|
|
|
Account(const Account &other) = delete;
|
|
|
|
Account &operator=(const Account &other) = delete;
|
2019-04-30 11:12:30 +00:00
|
|
|
|
2019-06-06 09:37:12 +00:00
|
|
|
void createSession(const MTPUser &user);
|
|
|
|
void destroySession();
|
|
|
|
|
2019-07-24 08:46:23 +00:00
|
|
|
void logOut();
|
|
|
|
void forcedLogOut();
|
|
|
|
|
2019-04-30 11:12:30 +00:00
|
|
|
[[nodiscard]] bool sessionExists() const;
|
2019-07-24 11:45:24 +00:00
|
|
|
[[nodiscard]] Session &session();
|
|
|
|
[[nodiscard]] const Session &session() const;
|
|
|
|
[[nodiscard]] rpl::producer<Session*> sessionValue() const;
|
|
|
|
[[nodiscard]] rpl::producer<Session*> sessionChanges() const;
|
2019-04-30 11:12:30 +00:00
|
|
|
|
2019-07-24 08:46:23 +00:00
|
|
|
[[nodiscard]] MTP::Instance *mtp() {
|
|
|
|
return _mtp.get();
|
|
|
|
}
|
|
|
|
[[nodiscard]] rpl::producer<MTP::Instance*> mtpValue() const;
|
|
|
|
[[nodiscard]] rpl::producer<MTP::Instance*> mtpChanges() const;
|
|
|
|
|
|
|
|
// Set from legacy storage.
|
|
|
|
void setMtpMainDcId(MTP::DcId mainDcId);
|
|
|
|
void setMtpKey(MTP::DcId dcId, const MTP::AuthKey::Data &keyData);
|
2019-07-24 11:45:24 +00:00
|
|
|
void setSessionUserId(UserId userId);
|
|
|
|
void setSessionFromStorage(
|
|
|
|
std::unique_ptr<Settings> data,
|
2019-07-24 08:46:23 +00:00
|
|
|
QByteArray &&selfSerialized,
|
|
|
|
int32 selfStreamVersion);
|
2019-07-24 11:45:24 +00:00
|
|
|
[[nodiscard]] Settings *getSessionSettings();
|
2019-07-24 08:46:23 +00:00
|
|
|
|
|
|
|
// Serialization.
|
|
|
|
[[nodiscard]] QByteArray serializeMtpAuthorization() const;
|
|
|
|
void setMtpAuthorization(const QByteArray &serialized);
|
|
|
|
|
|
|
|
void startMtp();
|
|
|
|
void suggestMainDcId(MTP::DcId mainDcId);
|
|
|
|
void destroyStaleAuthorizationKeys();
|
|
|
|
void configUpdated();
|
|
|
|
[[nodiscard]] rpl::producer<> configUpdates() const;
|
|
|
|
void clearMtp();
|
2019-04-30 11:12:30 +00:00
|
|
|
|
|
|
|
private:
|
2019-07-24 08:46:23 +00:00
|
|
|
void watchProxyChanges();
|
|
|
|
void watchSessionChanges();
|
|
|
|
|
|
|
|
void destroyMtpKeys(MTP::AuthKeysList &&keys);
|
|
|
|
void allKeysDestroyed();
|
|
|
|
void resetAuthorizationKeys();
|
|
|
|
|
|
|
|
void loggedOut();
|
|
|
|
|
|
|
|
std::unique_ptr<MTP::Instance> _mtp;
|
|
|
|
rpl::variable<MTP::Instance*> _mtpValue;
|
|
|
|
std::unique_ptr<MTP::Instance> _mtpForKeysDestroy;
|
|
|
|
rpl::event_stream<> _configUpdates;
|
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
std::unique_ptr<Session> _session;
|
|
|
|
rpl::variable<Session*> _sessionValue;
|
2019-04-30 11:12:30 +00:00
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
UserId _sessionUserId = 0;
|
|
|
|
QByteArray _sessionUserSerialized;
|
|
|
|
int32 _sessionUserStreamVersion = 0;
|
|
|
|
std::unique_ptr<Settings> _storedSettings;
|
2019-07-24 08:46:23 +00:00
|
|
|
MTP::Instance::Config _mtpConfig;
|
|
|
|
MTP::AuthKeysList _mtpKeysToDestroy;
|
|
|
|
|
|
|
|
rpl::lifetime _lifetime;
|
|
|
|
|
2019-04-30 11:12:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Main
|