From 81862215b4e823588d036ecb4cb6d6ee380c7a4a Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 19 Mar 2019 14:39:19 +0400 Subject: [PATCH] Add forwards and profile photo privacy settings. --- Telegram/Resources/langs/lang.strings | 19 ++++ Telegram/SourceFiles/apiwrap.cpp | 8 ++ Telegram/SourceFiles/apiwrap.h | 2 + Telegram/SourceFiles/settings/settings.style | 1 + .../settings/settings_privacy_controllers.cpp | 86 ++++++++++++++++++- .../settings/settings_privacy_controllers.h | 41 ++++++++- .../settings/settings_privacy_security.cpp | 8 ++ 7 files changed, 160 insertions(+), 5 deletions(-) diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index e123220c5..06cc05ecd 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -359,6 +359,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_settings_calls_peer_to_peer" = "Peer-to-peer in calls"; "lng_settings_groups_invite" = "Groups"; "lng_settings_group_privacy_about" = "Change who can add you to groups and channels."; +"lng_settings_forwards_privacy" = "Forwarded messages"; +"lng_settings_profile_photo_privacy" = "Profile photo"; "lng_settings_sessions_about" = "Control your sessions on other devices."; "lng_settings_passcode_disable" = "Disable passcode"; "lng_settings_password_disable" = "Disable cloud password"; @@ -640,6 +642,23 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_edit_privacy_calls_p2p_contacts" = "My contacts"; "lng_edit_privacy_calls_p2p_nobody" = "Nobody"; +"lng_edit_privacy_forwards_title" = "Forwarded messages privacy"; +"lng_edit_privacy_forwards_header" = "Who can add link to my account when forwarding my messages"; +"lng_edit_privacy_forwards_warning" = "When forwarded to other chats, messages you send will not link back to your account."; +"lng_edit_privacy_forwards_always_empty" = "Always allow"; +"lng_edit_privacy_forwards_never_empty" = "Never allow"; +"lng_edit_privacy_forwards_exceptions" = "These settings will override the values above."; +"lng_edit_privacy_forwards_always_title" = "Always allow"; +"lng_edit_privacy_forwards_never_title" = "Never allow"; + +"lng_edit_privacy_profile_photo_title" = "Profile photo privacy"; +"lng_edit_privacy_profile_photo_header" = "Who can see my profile photo"; +"lng_edit_privacy_profile_photo_always_empty" = "Always allow"; +"lng_edit_privacy_profile_photo_never_empty" = "Never allow"; +"lng_edit_privacy_profile_photo_exceptions" = "These settings will override the values above."; +"lng_edit_privacy_profile_photo_always_title" = "Always allow"; +"lng_edit_privacy_profile_photo_never_title" = "Never allow"; + "lng_self_destruct_title" = "Account self-destruction"; "lng_self_destruct_description" = "If you don't come online at least once within this period, your account will be deleted along with all groups, messages and contacts."; "lng_self_destruct_months#one" = "{count} month"; diff --git a/Telegram/SourceFiles/apiwrap.cpp b/Telegram/SourceFiles/apiwrap.cpp index 34b28c9ce..70aa20ed3 100644 --- a/Telegram/SourceFiles/apiwrap.cpp +++ b/Telegram/SourceFiles/apiwrap.cpp @@ -176,6 +176,10 @@ MTPInputPrivacyKey ApiWrap::Privacy::Input(Key key) { return MTP_inputPrivacyKeyStatusTimestamp(); case Privacy::Key::CallsPeer2Peer: return MTP_inputPrivacyKeyPhoneP2P(); + case Privacy::Key::Forwards: + return MTP_inputPrivacyKeyForwards(); + case Privacy::Key::ProfilePhoto: + return MTP_inputPrivacyKeyProfilePhoto(); } Unexpected("Key in ApiWrap::Privacy::Input."); } @@ -2211,6 +2215,10 @@ void ApiWrap::handlePrivacyChange( case mtpc_inputPrivacyKeyPhoneCall: return Key::Calls; case mtpc_privacyKeyPhoneP2P: case mtpc_inputPrivacyKeyPhoneP2P: return Key::CallsPeer2Peer; + case mtpc_privacyKeyForwards: + case mtpc_inputPrivacyKeyForwards: return Key::Forwards; + case mtpc_privacyKeyProfilePhoto: + case mtpc_inputPrivacyKeyProfilePhoto: return Key::ProfilePhoto; } return std::nullopt; }(); diff --git a/Telegram/SourceFiles/apiwrap.h b/Telegram/SourceFiles/apiwrap.h index b4d88fe59..bb44fe8a0 100644 --- a/Telegram/SourceFiles/apiwrap.h +++ b/Telegram/SourceFiles/apiwrap.h @@ -379,6 +379,8 @@ public: Calls, Invites, CallsPeer2Peer, + Forwards, + ProfilePhoto, }; enum class Option { Everyone, diff --git a/Telegram/SourceFiles/settings/settings.style b/Telegram/SourceFiles/settings/settings.style index 8b5dcf7cd..6f68d7ea0 100644 --- a/Telegram/SourceFiles/settings/settings.style +++ b/Telegram/SourceFiles/settings/settings.style @@ -85,6 +85,7 @@ settingsSubsectionTitle: FlatLabel(defaultFlatLabel) { linkFontOver: font(boxFontSize semibold underline); } textFg: windowActiveTextFg; + minWidth: 240px; } settingsSubsectionTitlePadding: margins(22px, 7px, 10px, 9px); settingsBackgroundPadding: margins(22px, 11px, 10px, 12px); diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp index 53c637c63..7405cc179 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.cpp @@ -290,7 +290,11 @@ void LastSeenPrivacyController::confirmSave(bool someAreDisallowed, FnMut(lang(lng_edit_privacy_lastseen_warning), lang(lng_continue), lang(lng_cancel), std::move(callback)); + auto box = Box( + lang(lng_edit_privacy_lastseen_warning), + lang(lng_continue), + lang(lng_cancel), + std::move(callback)); *weakBox = Ui::show(std::move(box), LayerOption::KeepOther); } else { saveCallback(); @@ -427,4 +431,84 @@ rpl::producer CallsPeer2PeerPrivacyController::exceptionsDescription() return Lang::Viewer(lng_edit_privacy_calls_p2p_exceptions); } +ApiWrap::Privacy::Key ForwardsPrivacyController::key() { + return Key::Forwards; +} + +MTPInputPrivacyKey ForwardsPrivacyController::apiKey() { + return MTP_inputPrivacyKeyForwards(); +} + +QString ForwardsPrivacyController::title() { + return lang(lng_edit_privacy_forwards_title); +} + +LangKey ForwardsPrivacyController::optionsTitleKey() { + return lng_edit_privacy_forwards_header; +} + +rpl::producer ForwardsPrivacyController::warning() { + return Lang::Viewer(lng_edit_privacy_forwards_warning); +} + +LangKey ForwardsPrivacyController::exceptionButtonTextKey( + Exception exception) { + switch (exception) { + case Exception::Always: return lng_edit_privacy_forwards_always_empty; + case Exception::Never: return lng_edit_privacy_forwards_never_empty; + } + Unexpected("Invalid exception value."); +} + +QString ForwardsPrivacyController::exceptionBoxTitle(Exception exception) { + switch (exception) { + case Exception::Always: return lang(lng_edit_privacy_forwards_always_title); + case Exception::Never: return lang(lng_edit_privacy_forwards_never_title); + } + Unexpected("Invalid exception value."); +} + +auto ForwardsPrivacyController::exceptionsDescription() +-> rpl::producer { + return Lang::Viewer(lng_edit_privacy_forwards_exceptions); +} + +ApiWrap::Privacy::Key ProfilePhotoPrivacyController::key() { + return Key::ProfilePhoto; +} + +MTPInputPrivacyKey ProfilePhotoPrivacyController::apiKey() { + return MTP_inputPrivacyKeyProfilePhoto(); +} + +QString ProfilePhotoPrivacyController::title() { + return lang(lng_edit_privacy_profile_photo_title); +} + +LangKey ProfilePhotoPrivacyController::optionsTitleKey() { + return lng_edit_privacy_profile_photo_header; +} + +LangKey ProfilePhotoPrivacyController::exceptionButtonTextKey( + Exception exception) { + switch (exception) { + case Exception::Always: return lng_edit_privacy_profile_photo_always_empty; + case Exception::Never: return lng_edit_privacy_profile_photo_never_empty; + } + Unexpected("Invalid exception value."); +} + +QString ProfilePhotoPrivacyController::exceptionBoxTitle(Exception exception) { + switch (exception) { + case Exception::Always: return lang(lng_edit_privacy_profile_photo_always_title); + case Exception::Never: return lang(lng_edit_privacy_profile_photo_never_title); + } + Unexpected("Invalid exception value."); +} + +auto ProfilePhotoPrivacyController::exceptionsDescription() +-> rpl::producer { + return Lang::Viewer(lng_edit_privacy_profile_photo_exceptions); +} + } // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_privacy_controllers.h b/Telegram/SourceFiles/settings/settings_privacy_controllers.h index 5f3d1ea52..3468e8b81 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_controllers.h +++ b/Telegram/SourceFiles/settings/settings_privacy_controllers.h @@ -36,7 +36,7 @@ private: }; -class LastSeenPrivacyController : public EditPrivacyBox::Controller, private base::Subscriber { +class LastSeenPrivacyController : public EditPrivacyBox::Controller { public: using Option = EditPrivacyBox::Option; using Exception = EditPrivacyBox::Exception; @@ -55,7 +55,7 @@ public: }; -class GroupsInvitePrivacyController : public EditPrivacyBox::Controller, private base::Subscriber { +class GroupsInvitePrivacyController : public EditPrivacyBox::Controller { public: using Option = EditPrivacyBox::Option; using Exception = EditPrivacyBox::Exception; @@ -72,7 +72,7 @@ public: }; -class CallsPrivacyController : public EditPrivacyBox::Controller, private base::Subscriber { +class CallsPrivacyController : public EditPrivacyBox::Controller { public: using Option = EditPrivacyBox::Option; using Exception = EditPrivacyBox::Exception; @@ -88,7 +88,7 @@ public: }; -class CallsPeer2PeerPrivacyController : public EditPrivacyBox::Controller, private base::Subscriber { +class CallsPeer2PeerPrivacyController : public EditPrivacyBox::Controller { public: using Option = EditPrivacyBox::Option; using Exception = EditPrivacyBox::Exception; @@ -106,4 +106,37 @@ public: }; +class ForwardsPrivacyController : public EditPrivacyBox::Controller { +public: + using Option = EditPrivacyBox::Option; + using Exception = EditPrivacyBox::Exception; + + Key key() override; + MTPInputPrivacyKey apiKey() override; + + QString title() override; + LangKey optionsTitleKey() override; + rpl::producer warning() override; + LangKey exceptionButtonTextKey(Exception exception) override; + QString exceptionBoxTitle(Exception exception) override; + rpl::producer exceptionsDescription() override; + +}; + +class ProfilePhotoPrivacyController : public EditPrivacyBox::Controller { +public: + using Option = EditPrivacyBox::Option; + using Exception = EditPrivacyBox::Exception; + + Key key() override; + MTPInputPrivacyKey apiKey() override; + + QString title() override; + LangKey optionsTitleKey() override; + LangKey exceptionButtonTextKey(Exception exception) override; + QString exceptionBoxTitle(Exception exception) override; + rpl::producer exceptionsDescription() override; + +}; + } // namespace Settings diff --git a/Telegram/SourceFiles/settings/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/settings_privacy_security.cpp index 9a84960c2..be7cd9575 100644 --- a/Telegram/SourceFiles/settings/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/settings_privacy_security.cpp @@ -139,6 +139,14 @@ void SetupPrivacy(not_null container) { lng_settings_last_seen, Privacy::Key::LastSeen, [] { return std::make_unique(); }); + add( + lng_settings_forwards_privacy, + Privacy::Key::Forwards, + [] { return std::make_unique(); }); + add( + lng_settings_profile_photo_privacy, + Privacy::Key::ProfilePhoto, + [] { return std::make_unique(); }); add( lng_settings_calls, Privacy::Key::Calls,