/* 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 "data/data_chat.h" #include "data/data_channel.h" #include "auth_session.h" #include "apiwrap.h" #include "styles/style_settings.h" #include "styles/style_boxes.h" namespace Settings { namespace { using Privacy = ApiWrap::Privacy; rpl::producer<> PasscodeChanges() { return rpl::single( rpl::empty_value() ) | rpl::then(base::ObservableViewer( Global::RefLocalPasscodeChanged() )); } QString PrivacyBase(Privacy::Key key, Privacy::Option option) { const auto phrase = [&] { using Key = Privacy::Key; using Option = 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); } rpl::producer 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 = ExceptionUsersCount(value.never)) { add.push_back("-" + QString::number(never)); } if (const auto always = ExceptionUsersCount(value.always)) { add.push_back("+" + QString::number(always)); } if (!add.isEmpty()) { return PrivacyBase(key, value.option) + " (" + add.join(", ") + ")"; } else { return PrivacyBase(key, value.option); } }); } rpl::producer BlockedUsersCount() { Auth().api().reloadBlockedUsers(); return Auth().api().blockedUsersSlice( ) | rpl::map([=](const ApiWrap::BlockedUsersSlice &data) { return data.total; }); } void SetupPrivacy(not_null container) { AddSkip(container, st::settingsPrivacySkip); AddSubsectionTitle(container, lng_settings_privacy_title); auto count = BlockedUsersCount( ) | rpl::map([](int count) { return count ? QString::number(count) : QString(); }); AddButtonWithLabel( container, lng_settings_blocked_users, std::move(count), 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 Key = Privacy::Key; const auto add = [&](LangKey label, Key key, auto controller) { AddPrivacyButton(container, label, key, controller); }; add( lng_settings_phone_number_privacy, Key::PhoneNumber, [] { return std::make_unique(); }); add( lng_settings_last_seen, Key::LastSeen, [] { return std::make_unique(); }); add( lng_settings_forwards_privacy, Key::Forwards, [] { return std::make_unique(); }); add( lng_settings_profile_photo_privacy, Key::ProfilePhoto, [] { return std::make_unique(); }); add( lng_settings_calls, Key::Calls, [] { return std::make_unique(); }); add( lng_settings_groups_invite, 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