From e737fa59b371b067d8814ba928d45c1a0c9f6b3f Mon Sep 17 00:00:00 2001 From: John Preston Date: Sun, 4 Nov 2018 20:51:59 +0400 Subject: [PATCH] Submit local Peer2PeerNobody setting to the cloud. --- Telegram/SourceFiles/auth_session.cpp | 28 +++++++++++++-------- Telegram/SourceFiles/auth_session.h | 18 +++---------- Telegram/SourceFiles/calls/calls_instance.h | 8 ------ Telegram/SourceFiles/messenger.cpp | 2 +- 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/Telegram/SourceFiles/auth_session.cpp b/Telegram/SourceFiles/auth_session.cpp index 1eb8bb80a..a78833585 100644 --- a/Telegram/SourceFiles/auth_session.cpp +++ b/Telegram/SourceFiles/auth_session.cpp @@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL namespace { constexpr auto kAutoLockTimeoutLateMs = TimeMs(3000); +constexpr auto kLegacyCallsPeerToPeerNobody = 4; } // namespace @@ -78,7 +79,7 @@ QByteArray AuthSessionSettings::serialize() const { stream << qint32(_variables.thirdColumnWidth.current()); stream << qint32(_variables.thirdSectionExtendedBy); stream << qint32(_variables.sendFilesWay); - stream << qint32(_variables.callsPeerToPeer.current()); + stream << qint32(0);// LEGACY _variables.callsPeerToPeer.current()); stream << qint32(_variables.sendSubmitWay); stream << qint32(_variables.supportSwitch); stream << qint32(_variables.supportFixChatsOrder ? 1 : 0); @@ -109,7 +110,7 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) int thirdColumnWidth = _variables.thirdColumnWidth.current(); int thirdSectionExtendedBy = _variables.thirdSectionExtendedBy; qint32 sendFilesWay = static_cast(_variables.sendFilesWay); - qint32 callsPeerToPeer = qint32(_variables.callsPeerToPeer.current()); + qint32 legacyCallsPeerToPeer = qint32(0); qint32 sendSubmitWay = static_cast(_variables.sendSubmitWay); qint32 supportSwitch = static_cast(_variables.supportSwitch); qint32 supportFixChatsOrder = _variables.supportFixChatsOrder ? 1 : 0; @@ -168,7 +169,7 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) stream >> sendFilesWay; } if (!stream.atEnd()) { - stream >> callsPeerToPeer; + stream >> legacyCallsPeerToPeer; } if (!stream.atEnd()) { stream >> sendSubmitWay; @@ -225,14 +226,6 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) case SendFilesWay::Photos: case SendFilesWay::Files: _variables.sendFilesWay = uncheckedSendFilesWay; break; } - auto uncheckedCallsPeerToPeer = static_cast(callsPeerToPeer); - switch (uncheckedCallsPeerToPeer) { - case Calls::PeerToPeer::DefaultContacts: - case Calls::PeerToPeer::DefaultEveryone: - case Calls::PeerToPeer::Everyone: - case Calls::PeerToPeer::Contacts: - case Calls::PeerToPeer::Nobody: _variables.callsPeerToPeer = uncheckedCallsPeerToPeer; break; - } auto uncheckedSendSubmitWay = static_cast( sendSubmitWay); switch (uncheckedSendSubmitWay) { @@ -249,6 +242,7 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized) _variables.supportFixChatsOrder = (supportFixChatsOrder == 1); _variables.supportTemplatesAutocomplete = (supportTemplatesAutocomplete == 1); _variables.supportChatsTimeSlice = supportChatsTimeSlice; + _variables.hadLegacyCallsPeerToPeerNobody = (legacyCallsPeerToPeer == kLegacyCallsPeerToPeerNobody); } void AuthSessionSettings::setSupportChatsTimeSlice(int slice) { @@ -416,6 +410,18 @@ bool AuthSession::validateSelf(const MTPUser &user) { return true; } +void AuthSession::moveSettingsFrom(AuthSessionSettings &&other) { + _settings.moveFrom(std::move(other)); + if (_settings.hadLegacyCallsPeerToPeerNobody()) { + api().savePrivacy( + MTP_inputPrivacyKeyPhoneP2P(), + QVector( + 1, + MTP_inputPrivacyValueDisallowAll())); + saveSettingsDelayed(); + } +} + void AuthSession::saveSettingsDelayed(TimeMs delay) { Expects(this == &Auth()); diff --git a/Telegram/SourceFiles/auth_session.h b/Telegram/SourceFiles/auth_session.h index a63bed5db..1c72c376f 100644 --- a/Telegram/SourceFiles/auth_session.h +++ b/Telegram/SourceFiles/auth_session.h @@ -28,10 +28,6 @@ namespace Data { class Session; } // namespace Data -namespace Calls { -enum class PeerToPeer; -} // namespace Calls - namespace Storage { class Downloader; class Uploader; @@ -186,14 +182,8 @@ public: _variables.groupStickersSectionHidden.remove(peerId); } - rpl::producer callsPeerToPeerValue() const { - return _variables.callsPeerToPeer.value(); - } - Calls::PeerToPeer callsPeerToPeer() const { - return _variables.callsPeerToPeer.current(); - } - void setCallsPeerToPeer(Calls::PeerToPeer value) { - _variables.callsPeerToPeer = value; + bool hadLegacyCallsPeerToPeerNobody() const { + return _variables.hadLegacyCallsPeerToPeerNobody; } private: @@ -219,9 +209,8 @@ private: = kDefaultDialogsWidthRatio; // per-window rpl::variable thirdColumnWidth = kDefaultThirdColumnWidth; // per-window - rpl::variable callsPeerToPeer - = Calls::PeerToPeer(); Ui::InputSubmitSettings sendSubmitWay; + bool hadLegacyCallsPeerToPeerNobody = false; static constexpr auto kDefaultSupportChatsLimitSlice = 30 * 24 * 60 * 60; @@ -290,6 +279,7 @@ public: AuthSessionSettings &settings() { return _settings; } + void moveSettingsFrom(AuthSessionSettings &&other); void saveSettingsDelayed(TimeMs delay = kDefaultSaveDelay); ApiWrap &api() { diff --git a/Telegram/SourceFiles/calls/calls_instance.h b/Telegram/SourceFiles/calls/calls_instance.h index 99f48b62c..92f49dc54 100644 --- a/Telegram/SourceFiles/calls/calls_instance.h +++ b/Telegram/SourceFiles/calls/calls_instance.h @@ -18,14 +18,6 @@ class Track; namespace Calls { -enum class PeerToPeer { - DefaultContacts, - DefaultEveryone, - Everyone, - Contacts, - Nobody, -}; - class Panel; class Instance : private MTP::Sender, private Call::Delegate, private base::Subscriber, public base::has_weak_ptr { diff --git a/Telegram/SourceFiles/messenger.cpp b/Telegram/SourceFiles/messenger.cpp index 178b38dd9..ba4ceea4b 100644 --- a/Telegram/SourceFiles/messenger.cpp +++ b/Telegram/SourceFiles/messenger.cpp @@ -499,7 +499,7 @@ void Messenger::startMtp() { } if (_private->storedAuthSession) { if (_authSession) { - _authSession->settings().moveFrom( + _authSession->moveSettingsFrom( std::move(*_private->storedAuthSession)); } _private->storedAuthSession.reset();