mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-09-05 09:05:14 +00:00
Move MTP::Instance to Main::Account.
This commit is contained in:
@@ -7,11 +7,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "mtproto/auth_key.h"
|
||||
#include "base/weak_ptr.h"
|
||||
|
||||
class AuthSession;
|
||||
class AuthSessionSettings;
|
||||
|
||||
namespace Main {
|
||||
|
||||
class Account final {
|
||||
class Account final : public base::has_weak_ptr {
|
||||
public:
|
||||
explicit Account(const QString &dataName);
|
||||
~Account();
|
||||
@@ -22,17 +26,69 @@ public:
|
||||
void createSession(const MTPUser &user);
|
||||
void destroySession();
|
||||
|
||||
void logOut();
|
||||
void forcedLogOut();
|
||||
|
||||
[[nodiscard]] bool sessionExists() const;
|
||||
[[nodiscard]] AuthSession &session();
|
||||
[[nodiscard]] const AuthSession &session() const;
|
||||
[[nodiscard]] rpl::producer<AuthSession*> sessionValue() const;
|
||||
[[nodiscard]] rpl::producer<AuthSession*> sessionChanges() const;
|
||||
|
||||
[[nodiscard]] MTP::Instance *mtp();
|
||||
[[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);
|
||||
void setAuthSessionUserId(UserId userId);
|
||||
void setAuthSessionFromStorage(
|
||||
std::unique_ptr<AuthSessionSettings> data,
|
||||
QByteArray &&selfSerialized,
|
||||
int32 selfStreamVersion);
|
||||
[[nodiscard]] AuthSessionSettings *getAuthSessionSettings();
|
||||
|
||||
// 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();
|
||||
|
||||
private:
|
||||
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;
|
||||
|
||||
std::unique_ptr<AuthSession> _session;
|
||||
rpl::variable<AuthSession*> _sessionValue;
|
||||
|
||||
UserId _authSessionUserId = 0;
|
||||
QByteArray _authSessionUserSerialized;
|
||||
int32 _authSessionUserStreamVersion = 0;
|
||||
std::unique_ptr<AuthSessionSettings> _storedAuthSession;
|
||||
MTP::Instance::Config _mtpConfig;
|
||||
MTP::AuthKeysList _mtpKeysToDestroy;
|
||||
|
||||
rpl::lifetime _lifetime;
|
||||
|
||||
};
|
||||
|
||||
} // namespace Main
|
||||
|
Reference in New Issue
Block a user