Version 1.8.12: Apply user settings in Session().

Fixes #6617.
This commit is contained in:
John Preston 2019-10-02 13:46:02 +03:00
parent ecfe1dacb2
commit af818b40aa
6 changed files with 78 additions and 53 deletions

View file

@ -123,7 +123,6 @@ public:
[[nodiscard]] Settings &settings() {
return _settings;
}
void moveSettingsFrom(Settings &&other);
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
// Dc options and proxy.

View file

@ -77,13 +77,52 @@ void Account::watchSessionChanges() {
}
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(_session == nullptr);
Expects(_sessionValue.current() == nullptr);
_mtp->setUpdatesHandler(::rpcDone([](
const mtpPrime *from,
const mtpPrime *end) {
const mtpPrime *from,
const mtpPrime *end) {
if (const auto main = App::main()) {
return main->updateReceived(from, end);
}
@ -96,8 +135,13 @@ void Account::createSession(const MTPUser &user) {
return true;
}));
_session = std::make_unique<Session>(this, user);
_session = std::make_unique<Session>(this, user, std::move(settings));
_sessionValue = _session.get();
if (!serialized.isEmpty()) {
// For now it depends on Auth() which depends on _sessionValue.
Local::readSelf(serialized, streamVersion);
}
}
void Account::destroySession() {
@ -316,39 +360,13 @@ void Account::startMtp() {
}
if (_sessionUserId) {
DEBUG_LOG(("sessionUserSerialized.size: %1"
).arg(_sessionUserSerialized.size()));
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(
createSession(
_sessionUserId,
base::take(_sessionUserSerialized),
base::take(_sessionUserStreamVersion));
}
if (_storedSettings) {
if (sessionExists()) {
session().moveSettingsFrom(std::move(*_storedSettings));
}
_storedSettings.reset();
base::take(_sessionUserStreamVersion),
_storedSettings ? std::move(*_storedSettings) : Settings());
}
_storedSettings = nullptr;
if (sessionExists()) {
// Skip all pending self updates so that we won't Local::writeSelf.

View file

@ -24,6 +24,11 @@ public:
Account &operator=(const Account &other) = delete;
void createSession(const MTPUser &user);
void createSession(
UserId id,
QByteArray serialized,
int streamVersion,
Settings &&settings);
void destroySession();
void logOut();
@ -63,6 +68,11 @@ public:
void clearMtp();
private:
void createSession(
const MTPUser &user,
QByteArray serialized,
int streamVersion,
Settings &&settings);
void watchProxyChanges();
void watchSessionChanges();

View file

@ -37,8 +37,10 @@ constexpr auto kLegacyCallsPeerToPeerNobody = 4;
Session::Session(
not_null<Main::Account*> account,
const MTPUser &user)
const MTPUser &user,
Settings &&settings)
: _account(account)
, _settings(std::move(settings))
, _saveSettingsTimer([=] { Local::writeUserSettings(); })
, _autoLockTimer([=] { checkAutoLock(); })
, _api(std::make_unique<ApiWrap>(this))
@ -84,6 +86,15 @@ Session::Session(
Local::writeSelf();
}
}));
if (_settings.hadLegacyCallsPeerToPeerNobody()) {
api().savePrivacy(
MTP_inputPrivacyKeyPhoneP2P(),
QVector<MTPInputPrivacyRule>(
1,
MTP_inputPrivacyValueDisallowAll()));
saveSettingsDelayed();
}
});
Window::Theme::Background()->start();
@ -127,18 +138,6 @@ bool Session::validateSelf(const MTPUser &user) {
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) {
Expects(this == &Auth());

View file

@ -57,7 +57,10 @@ class Session final
: public base::has_weak_ptr
, private base::Subscriber {
public:
Session(not_null<Main::Account*> account, const MTPUser &user);
Session(
not_null<Main::Account*> account,
const MTPUser &user,
Settings &&other);
~Session();
Session(const Session &other) = delete;
@ -102,7 +105,6 @@ public:
[[nodiscard]] Settings &settings() {
return _settings;
}
void moveSettingsFrom(Settings &&other);
void saveSettingsDelayed(crl::time delay = kDefaultSaveDelay);
[[nodiscard]] not_null<MTP::Instance*> mtp();

View file

@ -32,9 +32,6 @@ namespace Main {
class Settings final {
public:
void moveFrom(Settings &&other) {
_variables = std::move(other._variables);
}
[[nodiscard]] QByteArray serialize() const;
void constructFromSerialized(const QByteArray &serialized);