Submit local Peer2PeerNobody setting to the cloud.

This commit is contained in:
John Preston 2018-11-04 20:51:59 +04:00
parent 8d27d8efcf
commit e737fa59b3
4 changed files with 22 additions and 34 deletions

View File

@ -31,6 +31,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace { namespace {
constexpr auto kAutoLockTimeoutLateMs = TimeMs(3000); constexpr auto kAutoLockTimeoutLateMs = TimeMs(3000);
constexpr auto kLegacyCallsPeerToPeerNobody = 4;
} // namespace } // namespace
@ -78,7 +79,7 @@ QByteArray AuthSessionSettings::serialize() const {
stream << qint32(_variables.thirdColumnWidth.current()); stream << qint32(_variables.thirdColumnWidth.current());
stream << qint32(_variables.thirdSectionExtendedBy); stream << qint32(_variables.thirdSectionExtendedBy);
stream << qint32(_variables.sendFilesWay); stream << qint32(_variables.sendFilesWay);
stream << qint32(_variables.callsPeerToPeer.current()); stream << qint32(0);// LEGACY _variables.callsPeerToPeer.current());
stream << qint32(_variables.sendSubmitWay); stream << qint32(_variables.sendSubmitWay);
stream << qint32(_variables.supportSwitch); stream << qint32(_variables.supportSwitch);
stream << qint32(_variables.supportFixChatsOrder ? 1 : 0); stream << qint32(_variables.supportFixChatsOrder ? 1 : 0);
@ -109,7 +110,7 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized)
int thirdColumnWidth = _variables.thirdColumnWidth.current(); int thirdColumnWidth = _variables.thirdColumnWidth.current();
int thirdSectionExtendedBy = _variables.thirdSectionExtendedBy; int thirdSectionExtendedBy = _variables.thirdSectionExtendedBy;
qint32 sendFilesWay = static_cast<qint32>(_variables.sendFilesWay); qint32 sendFilesWay = static_cast<qint32>(_variables.sendFilesWay);
qint32 callsPeerToPeer = qint32(_variables.callsPeerToPeer.current()); qint32 legacyCallsPeerToPeer = qint32(0);
qint32 sendSubmitWay = static_cast<qint32>(_variables.sendSubmitWay); qint32 sendSubmitWay = static_cast<qint32>(_variables.sendSubmitWay);
qint32 supportSwitch = static_cast<qint32>(_variables.supportSwitch); qint32 supportSwitch = static_cast<qint32>(_variables.supportSwitch);
qint32 supportFixChatsOrder = _variables.supportFixChatsOrder ? 1 : 0; qint32 supportFixChatsOrder = _variables.supportFixChatsOrder ? 1 : 0;
@ -168,7 +169,7 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized)
stream >> sendFilesWay; stream >> sendFilesWay;
} }
if (!stream.atEnd()) { if (!stream.atEnd()) {
stream >> callsPeerToPeer; stream >> legacyCallsPeerToPeer;
} }
if (!stream.atEnd()) { if (!stream.atEnd()) {
stream >> sendSubmitWay; stream >> sendSubmitWay;
@ -225,14 +226,6 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized)
case SendFilesWay::Photos: case SendFilesWay::Photos:
case SendFilesWay::Files: _variables.sendFilesWay = uncheckedSendFilesWay; break; case SendFilesWay::Files: _variables.sendFilesWay = uncheckedSendFilesWay; break;
} }
auto uncheckedCallsPeerToPeer = static_cast<Calls::PeerToPeer>(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<Ui::InputSubmitSettings>( auto uncheckedSendSubmitWay = static_cast<Ui::InputSubmitSettings>(
sendSubmitWay); sendSubmitWay);
switch (uncheckedSendSubmitWay) { switch (uncheckedSendSubmitWay) {
@ -249,6 +242,7 @@ void AuthSessionSettings::constructFromSerialized(const QByteArray &serialized)
_variables.supportFixChatsOrder = (supportFixChatsOrder == 1); _variables.supportFixChatsOrder = (supportFixChatsOrder == 1);
_variables.supportTemplatesAutocomplete = (supportTemplatesAutocomplete == 1); _variables.supportTemplatesAutocomplete = (supportTemplatesAutocomplete == 1);
_variables.supportChatsTimeSlice = supportChatsTimeSlice; _variables.supportChatsTimeSlice = supportChatsTimeSlice;
_variables.hadLegacyCallsPeerToPeerNobody = (legacyCallsPeerToPeer == kLegacyCallsPeerToPeerNobody);
} }
void AuthSessionSettings::setSupportChatsTimeSlice(int slice) { void AuthSessionSettings::setSupportChatsTimeSlice(int slice) {
@ -416,6 +410,18 @@ bool AuthSession::validateSelf(const MTPUser &user) {
return true; return true;
} }
void AuthSession::moveSettingsFrom(AuthSessionSettings &&other) {
_settings.moveFrom(std::move(other));
if (_settings.hadLegacyCallsPeerToPeerNobody()) {
api().savePrivacy(
MTP_inputPrivacyKeyPhoneP2P(),
QVector<MTPInputPrivacyRule>(
1,
MTP_inputPrivacyValueDisallowAll()));
saveSettingsDelayed();
}
}
void AuthSession::saveSettingsDelayed(TimeMs delay) { void AuthSession::saveSettingsDelayed(TimeMs delay) {
Expects(this == &Auth()); Expects(this == &Auth());

View File

@ -28,10 +28,6 @@ namespace Data {
class Session; class Session;
} // namespace Data } // namespace Data
namespace Calls {
enum class PeerToPeer;
} // namespace Calls
namespace Storage { namespace Storage {
class Downloader; class Downloader;
class Uploader; class Uploader;
@ -186,14 +182,8 @@ public:
_variables.groupStickersSectionHidden.remove(peerId); _variables.groupStickersSectionHidden.remove(peerId);
} }
rpl::producer<Calls::PeerToPeer> callsPeerToPeerValue() const { bool hadLegacyCallsPeerToPeerNobody() const {
return _variables.callsPeerToPeer.value(); return _variables.hadLegacyCallsPeerToPeerNobody;
}
Calls::PeerToPeer callsPeerToPeer() const {
return _variables.callsPeerToPeer.current();
}
void setCallsPeerToPeer(Calls::PeerToPeer value) {
_variables.callsPeerToPeer = value;
} }
private: private:
@ -219,9 +209,8 @@ private:
= kDefaultDialogsWidthRatio; // per-window = kDefaultDialogsWidthRatio; // per-window
rpl::variable<int> thirdColumnWidth rpl::variable<int> thirdColumnWidth
= kDefaultThirdColumnWidth; // per-window = kDefaultThirdColumnWidth; // per-window
rpl::variable<Calls::PeerToPeer> callsPeerToPeer
= Calls::PeerToPeer();
Ui::InputSubmitSettings sendSubmitWay; Ui::InputSubmitSettings sendSubmitWay;
bool hadLegacyCallsPeerToPeerNobody = false;
static constexpr auto kDefaultSupportChatsLimitSlice static constexpr auto kDefaultSupportChatsLimitSlice
= 30 * 24 * 60 * 60; = 30 * 24 * 60 * 60;
@ -290,6 +279,7 @@ public:
AuthSessionSettings &settings() { AuthSessionSettings &settings() {
return _settings; return _settings;
} }
void moveSettingsFrom(AuthSessionSettings &&other);
void saveSettingsDelayed(TimeMs delay = kDefaultSaveDelay); void saveSettingsDelayed(TimeMs delay = kDefaultSaveDelay);
ApiWrap &api() { ApiWrap &api() {

View File

@ -18,14 +18,6 @@ class Track;
namespace Calls { namespace Calls {
enum class PeerToPeer {
DefaultContacts,
DefaultEveryone,
Everyone,
Contacts,
Nobody,
};
class Panel; class Panel;
class Instance : private MTP::Sender, private Call::Delegate, private base::Subscriber, public base::has_weak_ptr { class Instance : private MTP::Sender, private Call::Delegate, private base::Subscriber, public base::has_weak_ptr {

View File

@ -499,7 +499,7 @@ void Messenger::startMtp() {
} }
if (_private->storedAuthSession) { if (_private->storedAuthSession) {
if (_authSession) { if (_authSession) {
_authSession->settings().moveFrom( _authSession->moveSettingsFrom(
std::move(*_private->storedAuthSession)); std::move(*_private->storedAuthSession));
} }
_private->storedAuthSession.reset(); _private->storedAuthSession.reset();