mirror of https://github.com/procxx/kepka.git
parent
ecfe1dacb2
commit
af818b40aa
|
@ -123,7 +123,6 @@ public:
|
||||||
[[nodiscard]] Settings &settings() {
|
[[nodiscard]] Settings &settings() {
|
||||||
return _settings;
|
return _settings;
|
||||||
}
|
}
|
||||||
void moveSettingsFrom(Settings &&other);
|
|
||||||
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
|
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
|
||||||
|
|
||||||
// Dc options and proxy.
|
// Dc options and proxy.
|
||||||
|
|
|
@ -77,13 +77,52 @@ void Account::watchSessionChanges() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Account::createSession(const MTPUser &user) {
|
void Account::createSession(const MTPUser &user) {
|
||||||
|
createSession(user, QByteArray(), 0, Settings());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Account::createSession(
|
||||||
|
UserId id,
|
||||||
|
QByteArray serialized,
|
||||||
|
int streamVersion,
|
||||||
|
Settings &&settings) {
|
||||||
|
DEBUG_LOG(("sessionUserSerialized.size: %1").arg(serialized.size()));
|
||||||
|
QDataStream peekStream(serialized);
|
||||||
|
const auto phone = Serialize::peekUserPhone(streamVersion, peekStream);
|
||||||
|
const auto flags = MTPDuser::Flag::f_self | (phone.isEmpty()
|
||||||
|
? MTPDuser::Flag()
|
||||||
|
: MTPDuser::Flag::f_phone);
|
||||||
|
createSession(
|
||||||
|
MTP_user(
|
||||||
|
MTP_flags(flags),
|
||||||
|
MTP_int(base::take(_sessionUserId)),
|
||||||
|
MTPlong(), // access_hash
|
||||||
|
MTPstring(), // first_name
|
||||||
|
MTPstring(), // last_name
|
||||||
|
MTPstring(), // username
|
||||||
|
MTP_string(phone),
|
||||||
|
MTPUserProfilePhoto(),
|
||||||
|
MTPUserStatus(),
|
||||||
|
MTPint(), // bot_info_version
|
||||||
|
MTPVector<MTPRestrictionReason>(),
|
||||||
|
MTPstring(), // bot_inline_placeholder
|
||||||
|
MTPstring()), // lang_code
|
||||||
|
serialized,
|
||||||
|
streamVersion,
|
||||||
|
std::move(settings));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Account::createSession(
|
||||||
|
const MTPUser &user,
|
||||||
|
QByteArray serialized,
|
||||||
|
int streamVersion,
|
||||||
|
Settings &&settings) {
|
||||||
Expects(_mtp != nullptr);
|
Expects(_mtp != nullptr);
|
||||||
Expects(_session == nullptr);
|
Expects(_session == nullptr);
|
||||||
Expects(_sessionValue.current() == nullptr);
|
Expects(_sessionValue.current() == nullptr);
|
||||||
|
|
||||||
_mtp->setUpdatesHandler(::rpcDone([](
|
_mtp->setUpdatesHandler(::rpcDone([](
|
||||||
const mtpPrime *from,
|
const mtpPrime *from,
|
||||||
const mtpPrime *end) {
|
const mtpPrime *end) {
|
||||||
if (const auto main = App::main()) {
|
if (const auto main = App::main()) {
|
||||||
return main->updateReceived(from, end);
|
return main->updateReceived(from, end);
|
||||||
}
|
}
|
||||||
|
@ -96,8 +135,13 @@ void Account::createSession(const MTPUser &user) {
|
||||||
return true;
|
return true;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
_session = std::make_unique<Session>(this, user);
|
_session = std::make_unique<Session>(this, user, std::move(settings));
|
||||||
_sessionValue = _session.get();
|
_sessionValue = _session.get();
|
||||||
|
|
||||||
|
if (!serialized.isEmpty()) {
|
||||||
|
// For now it depends on Auth() which depends on _sessionValue.
|
||||||
|
Local::readSelf(serialized, streamVersion);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Account::destroySession() {
|
void Account::destroySession() {
|
||||||
|
@ -316,39 +360,13 @@ void Account::startMtp() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_sessionUserId) {
|
if (_sessionUserId) {
|
||||||
DEBUG_LOG(("sessionUserSerialized.size: %1"
|
createSession(
|
||||||
).arg(_sessionUserSerialized.size()));
|
_sessionUserId,
|
||||||
QDataStream peekStream(_sessionUserSerialized);
|
|
||||||
const auto phone = Serialize::peekUserPhone(
|
|
||||||
_sessionUserStreamVersion,
|
|
||||||
peekStream);
|
|
||||||
const auto flags = MTPDuser::Flag::f_self | (phone.isEmpty()
|
|
||||||
? MTPDuser::Flag()
|
|
||||||
: MTPDuser::Flag::f_phone);
|
|
||||||
createSession(MTP_user(
|
|
||||||
MTP_flags(flags),
|
|
||||||
MTP_int(base::take(_sessionUserId)),
|
|
||||||
MTPlong(), // access_hash
|
|
||||||
MTPstring(), // first_name
|
|
||||||
MTPstring(), // last_name
|
|
||||||
MTPstring(), // username
|
|
||||||
MTP_string(phone),
|
|
||||||
MTPUserProfilePhoto(),
|
|
||||||
MTPUserStatus(),
|
|
||||||
MTPint(), // bot_info_version
|
|
||||||
MTPVector<MTPRestrictionReason>(),
|
|
||||||
MTPstring(), // bot_inline_placeholder
|
|
||||||
MTPstring())); // lang_code
|
|
||||||
Local::readSelf(
|
|
||||||
base::take(_sessionUserSerialized),
|
base::take(_sessionUserSerialized),
|
||||||
base::take(_sessionUserStreamVersion));
|
base::take(_sessionUserStreamVersion),
|
||||||
}
|
_storedSettings ? std::move(*_storedSettings) : Settings());
|
||||||
if (_storedSettings) {
|
|
||||||
if (sessionExists()) {
|
|
||||||
session().moveSettingsFrom(std::move(*_storedSettings));
|
|
||||||
}
|
|
||||||
_storedSettings.reset();
|
|
||||||
}
|
}
|
||||||
|
_storedSettings = nullptr;
|
||||||
|
|
||||||
if (sessionExists()) {
|
if (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.
|
||||||
|
|
|
@ -24,6 +24,11 @@ public:
|
||||||
Account &operator=(const Account &other) = delete;
|
Account &operator=(const Account &other) = delete;
|
||||||
|
|
||||||
void createSession(const MTPUser &user);
|
void createSession(const MTPUser &user);
|
||||||
|
void createSession(
|
||||||
|
UserId id,
|
||||||
|
QByteArray serialized,
|
||||||
|
int streamVersion,
|
||||||
|
Settings &&settings);
|
||||||
void destroySession();
|
void destroySession();
|
||||||
|
|
||||||
void logOut();
|
void logOut();
|
||||||
|
@ -63,6 +68,11 @@ public:
|
||||||
void clearMtp();
|
void clearMtp();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void createSession(
|
||||||
|
const MTPUser &user,
|
||||||
|
QByteArray serialized,
|
||||||
|
int streamVersion,
|
||||||
|
Settings &&settings);
|
||||||
void watchProxyChanges();
|
void watchProxyChanges();
|
||||||
void watchSessionChanges();
|
void watchSessionChanges();
|
||||||
|
|
||||||
|
|
|
@ -37,8 +37,10 @@ constexpr auto kLegacyCallsPeerToPeerNobody = 4;
|
||||||
|
|
||||||
Session::Session(
|
Session::Session(
|
||||||
not_null<Main::Account*> account,
|
not_null<Main::Account*> account,
|
||||||
const MTPUser &user)
|
const MTPUser &user,
|
||||||
|
Settings &&settings)
|
||||||
: _account(account)
|
: _account(account)
|
||||||
|
, _settings(std::move(settings))
|
||||||
, _saveSettingsTimer([=] { Local::writeUserSettings(); })
|
, _saveSettingsTimer([=] { Local::writeUserSettings(); })
|
||||||
, _autoLockTimer([=] { checkAutoLock(); })
|
, _autoLockTimer([=] { checkAutoLock(); })
|
||||||
, _api(std::make_unique<ApiWrap>(this))
|
, _api(std::make_unique<ApiWrap>(this))
|
||||||
|
@ -84,6 +86,15 @@ Session::Session(
|
||||||
Local::writeSelf();
|
Local::writeSelf();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
if (_settings.hadLegacyCallsPeerToPeerNobody()) {
|
||||||
|
api().savePrivacy(
|
||||||
|
MTP_inputPrivacyKeyPhoneP2P(),
|
||||||
|
QVector<MTPInputPrivacyRule>(
|
||||||
|
1,
|
||||||
|
MTP_inputPrivacyValueDisallowAll()));
|
||||||
|
saveSettingsDelayed();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Window::Theme::Background()->start();
|
Window::Theme::Background()->start();
|
||||||
|
@ -127,18 +138,6 @@ bool Session::validateSelf(const MTPUser &user) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::moveSettingsFrom(Settings &&other) {
|
|
||||||
_settings.moveFrom(std::move(other));
|
|
||||||
if (_settings.hadLegacyCallsPeerToPeerNobody()) {
|
|
||||||
api().savePrivacy(
|
|
||||||
MTP_inputPrivacyKeyPhoneP2P(),
|
|
||||||
QVector<MTPInputPrivacyRule>(
|
|
||||||
1,
|
|
||||||
MTP_inputPrivacyValueDisallowAll()));
|
|
||||||
saveSettingsDelayed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Session::saveSettingsDelayed(crl::time delay) {
|
void Session::saveSettingsDelayed(crl::time delay) {
|
||||||
Expects(this == &Auth());
|
Expects(this == &Auth());
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,10 @@ class Session final
|
||||||
: public base::has_weak_ptr
|
: public base::has_weak_ptr
|
||||||
, private base::Subscriber {
|
, private base::Subscriber {
|
||||||
public:
|
public:
|
||||||
Session(not_null<Main::Account*> account, const MTPUser &user);
|
Session(
|
||||||
|
not_null<Main::Account*> account,
|
||||||
|
const MTPUser &user,
|
||||||
|
Settings &&other);
|
||||||
~Session();
|
~Session();
|
||||||
|
|
||||||
Session(const Session &other) = delete;
|
Session(const Session &other) = delete;
|
||||||
|
@ -102,7 +105,6 @@ public:
|
||||||
[[nodiscard]] Settings &settings() {
|
[[nodiscard]] Settings &settings() {
|
||||||
return _settings;
|
return _settings;
|
||||||
}
|
}
|
||||||
void moveSettingsFrom(Settings &&other);
|
|
||||||
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
|
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
|
||||||
|
|
||||||
[[nodiscard]] not_null<MTP::Instance*> mtp();
|
[[nodiscard]] not_null<MTP::Instance*> mtp();
|
||||||
|
|
|
@ -32,9 +32,6 @@ namespace Main {
|
||||||
|
|
||||||
class Settings final {
|
class Settings final {
|
||||||
public:
|
public:
|
||||||
void moveFrom(Settings &&other) {
|
|
||||||
_variables = std::move(other._variables);
|
|
||||||
}
|
|
||||||
[[nodiscard]] QByteArray serialize() const;
|
[[nodiscard]] QByteArray serialize() const;
|
||||||
void constructFromSerialized(const QByteArray &serialized);
|
void constructFromSerialized(const QByteArray &serialized);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue