/* This file is part of Telegram Desktop, the official desktop application for the Telegram messaging service. For license and copyright information please follow this link: https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "settings/settings_privacy_security.h" #include "settings/settings_common.h" #include "settings/settings_privacy_controllers.h" #include "boxes/peer_list_box.h" #include "boxes/edit_privacy_box.h" #include "boxes/passcode_box.h" #include "boxes/auto_lock_box.h" #include "boxes/sessions_box.h" #include "boxes/confirm_box.h" #include "boxes/self_destruction_box.h" #include "ui/wrap/vertical_layout.h" #include "ui/wrap/slide_wrap.h" #include "ui/wrap/fade_wrap.h" #include "ui/widgets/shadow.h" #include "ui/widgets/labels.h" #include "calls/calls_instance.h" #include "core/core_cloud_password.h" #include "core/update_checker.h" #include "info/profile/info_profile_button.h" #include "platform/platform_specific.h" #include "lang/lang_keys.h" #include "data/data_session.h" #include "auth_session.h" #include "apiwrap.h" #include "styles/style_settings.h" #include "styles/style_boxes.h" namespace Settings { namespace { rpl::producer<> PasscodeChanges() { return rpl::single( rpl::empty_value() ) | rpl::then(base::ObservableViewer( Global::RefLocalPasscodeChanged() )); } QString PrivacyBase( ApiWrap::Privacy::Key key, ApiWrap::Privacy::Option option) { const auto phrase = [&] { using Key = ApiWrap::Privacy::Key; using Option = ApiWrap::Privacy::Option; switch (key) { case Key::CallsPeer2Peer: switch (option) { case Option::Everyone: return lng_edit_privacy_calls_p2p_everyone; case Option::Contacts: return lng_edit_privacy_calls_p2p_contacts; case Option::Nobody: return lng_edit_privacy_calls_p2p_nobody; } Unexpected("Value in Privacy::Option."); default: switch (option) { case Option::Everyone: return lng_edit_privacy_everyone; case Option::Contacts: return lng_edit_privacy_contacts; case Option::Nobody: return lng_edit_privacy_nobody; } Unexpected("Value in Privacy::Option."); } }(); return lang(phrase); } void SetupPrivacy(not_null container) { AddSkip(container, st::settingsPrivacySkip); AddSubsectionTitle(container, lng_settings_privacy_title); AddButton( container, lng_settings_blocked_users, st::settingsButton )->addClickHandler([] { const auto initBox = [](not_null box) { box->addButton(langFactory(lng_close), [=] { box->closeBox(); }); box->addLeftButton(langFactory(lng_blocked_list_add), [] { BlockedBoxController::BlockNewUser(); }); }; Ui::show(Box( std::make_unique(), initBox)); }); using Privacy = ApiWrap::Privacy; const auto PrivacyString = [](Privacy::Key key) { Auth().api().reloadPrivacy(key); return Auth().api().privacyValue( key ) | rpl::map([=](const Privacy &value) { auto add = QStringList(); if (const auto never = value.never.size()) { add.push_back("-" + QString::number(never)); } if (const auto always = value.always.size()) { add.push_back("+" + QString::number(always)); } if (!add.isEmpty()) { return PrivacyBase(key, value.option) + " (" + add.join(", ") + ")"; } else { return PrivacyBase(key, value.option); } }); }; const auto add = [&](LangKey label, Privacy::Key key, auto controller) { const auto shower = Ui::CreateChild(container.get()); AddButtonWithLabel( container, label, PrivacyString(key), st::settingsButton )->addClickHandler([=] { *shower = Auth().api().privacyValue( key ) | rpl::take( 1 ) | rpl::start_with_next([=](const Privacy &value) { Ui::show(Box( controller(), value)); }); }); }; add( lng_settings_last_seen, Privacy::Key::LastSeen, [] { return std::make_unique(); }); add( lng_settings_calls, Privacy::Key::Calls, [] { return std::make_unique(); }); add( lng_settings_calls_peer_to_peer, Privacy::Key::CallsPeer2Peer, [] { return std::make_unique(); }); add( lng_settings_groups_invite, Privacy::Key::Invites, [] { return std::make_unique(); }); AddSkip(container, st::settingsPrivacySecurityPadding); AddDividerText( container, Lang::Viewer(lng_settings_group_privacy_about)); } not_null*> AddSeparator( not_null container) { return container->add( object_ptr>( container, object_ptr(container), st::settingsSeparatorPadding)); } void SetupLocalPasscode(not_null container) { AddSkip(container); AddSubsectionTitle(container, lng_settings_passcode_title); auto has = PasscodeChanges( ) | rpl::map([] { return Global::LocalPasscode(); }); auto text = rpl::combine( Lang::Viewer(lng_passcode_change), Lang::Viewer(lng_passcode_turn_on), base::duplicate(has), [](const QString &change, const QString &create, bool has) { return has ? change : create; }); container->add( object_ptr