/* 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/sections/settings_privacy_security.h" #include "settings/settings_common_session.h" #include "api/api_authorizations.h" #include "api/api_blocked_peers.h" #include "api/api_cloud_password.h" #include "api/api_global_privacy.h" #include "api/api_self_destruct.h" #include "api/api_sensitive_content.h" #include "api/api_websites.h" #include "apiwrap.h" #include "base/system_unlock.h" #include "base/timer_rpl.h" #include "boxes/edit_privacy_box.h" #include "boxes/passcode_box.h" #include "boxes/self_destruction_box.h" #include "core/application.h" #include "core/click_handler_types.h" #include "core/core_cloud_password.h" #include "core/core_settings.h" #include "core/update_checker.h" #include "data/components/passkeys.h" #include "data/components/top_peers.h" #include "data/data_channel.h" #include "data/data_chat.h" #include "data/data_peer_values.h" #include "data/data_session.h" #include "history/view/media/history_view_media_common.h" #include "ui/chat/chat_style.h" #include "lang/lang_keys.h" #include "main/main_app_config.h" #include "main/main_domain.h" #include "main/main_session.h" #include "platform/platform_webauthn.h" #include "settings/settings_builder.h" #include "settings/cloud_password/settings_cloud_password_email_confirm.h" #include "settings/cloud_password/settings_cloud_password_input.h" #include "settings/cloud_password/settings_cloud_password_start.h" #include "settings/sections/settings_main.h" #include "settings/sections/settings_active_sessions.h" #include "settings/sections/settings_blocked_peers.h" #include "settings/sections/settings_global_ttl.h" #include "settings/sections/settings_local_passcode.h" #include "settings/sections/settings_passkeys.h" #include "settings/sections/settings_premium.h" #include "settings/settings_privacy_controllers.h" #include "settings/sections/settings_websites.h" #include "storage/storage_domain.h" #include "ui/boxes/confirm_box.h" #include "ui/effects/premium_graphics.h" #include "ui/layers/generic_box.h" #include "ui/rect.h" #include "ui/text/format_values.h" #include "ui/text/text_utilities.h" #include "ui/toast/toast.h" #include "ui/vertical_list.h" #include "ui/widgets/buttons.h" #include "ui/widgets/checkbox.h" #include "ui/widgets/fields/input_field.h" #include "ui/wrap/slide_wrap.h" #include "ui/wrap/vertical_layout.h" #include "window/window_session_controller.h" #include "styles/style_layers.h" #include "styles/style_menu_icons.h" #include "styles/style_settings.h" #include #include namespace Settings { namespace { constexpr auto kUpdateTimeout = 60 * crl::time(1000); using Privacy = Api::UserPrivacy; QString PrivacyBase(Privacy::Key key, const Privacy::Rule &rule) { using Key = Privacy::Key; using Option = Privacy::Option; switch (key) { case Key::CallsPeer2Peer: switch (rule.option) { case Option::Everyone: return tr::lng_edit_privacy_calls_p2p_everyone(tr::now); case Option::Contacts: return tr::lng_edit_privacy_calls_p2p_contacts(tr::now); case Option::Nobody: return tr::lng_edit_privacy_calls_p2p_nobody(tr::now); } [[fallthrough]]; default: switch (rule.option) { case Option::Everyone: return rule.never.miniapps ? tr::lng_edit_privacy_no_miniapps(tr::now) : tr::lng_edit_privacy_everyone(tr::now); case Option::Contacts: return rule.always.premiums ? tr::lng_edit_privacy_contacts_and_premium(tr::now) : rule.always.miniapps ? tr::lng_edit_privacy_contacts_and_miniapps(tr::now) : tr::lng_edit_privacy_contacts(tr::now); case Option::CloseFriends: return tr::lng_edit_privacy_close_friends(tr::now); case Option::Nobody: return rule.always.premiums ? tr::lng_edit_privacy_premium(tr::now) : rule.always.miniapps ? tr::lng_edit_privacy_miniapps(tr::now) : tr::lng_edit_privacy_nobody(tr::now); } Unexpected("Value in Privacy::Option."); } } rpl::producer PrivacyString( not_null<::Main::Session*> session, Privacy::Key key) { session->api().userPrivacy().reload(key); return session->api().userPrivacy().value( key ) | rpl::map([=](const Privacy::Rule &value) { auto add = QStringList(); if (const auto never = ExceptionUsersCount(value.never.peers)) { add.push_back("-" + QString::number(never)); } if (const auto always = ExceptionUsersCount(value.always.peers)) { add.push_back("+" + QString::number(always)); } if (!add.isEmpty()) { return PrivacyBase(key, value) + " (" + add.join(", ") + ")"; } else { return PrivacyBase(key, value); } }); } void ClearPaymentInfoBoxBuilder( not_null box, not_null<::Main::Session*> session) { box->setTitle(tr::lng_clear_payment_info_title()); const auto checkboxPadding = style::margins( st::boxRowPadding.left(), st::boxRowPadding.left(), st::boxRowPadding.right(), st::boxRowPadding.bottom()); const auto label = box->addRow(object_ptr( box, tr::lng_clear_payment_info_sure(), st::boxLabel)); const auto shipping = box->addRow( object_ptr( box, tr::lng_clear_payment_info_shipping(tr::now), true, st::defaultBoxCheckbox), checkboxPadding); const auto payment = box->addRow( object_ptr( box, tr::lng_clear_payment_info_payment(tr::now), true, st::defaultBoxCheckbox), checkboxPadding); using Flags = MTPpayments_ClearSavedInfo::Flags; const auto flags = box->lifetime().make_state(); box->addButton(tr::lng_clear_payment_info_clear(), [=] { using Flag = Flags::Enum; *flags = (shipping->checked() ? Flag::f_info : Flag(0)) | (payment->checked() ? Flag::f_credentials : Flag(0)); delete label; delete shipping; delete payment; box->addRow(object_ptr( box, tr::lng_clear_payment_info_confirm(), st::boxLabel)); box->clearButtons(); box->addButton(tr::lng_clear_payment_info_clear(), [=] { session->api().request(MTPpayments_ClearSavedInfo( MTP_flags(*flags) )).send(); box->closeBox(); }, st::attentionBoxButton); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); }, st::attentionBoxButton); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); }); } } // namespace rpl::producer PrivacyButtonLabel( not_null<::Main::Session*> session, Privacy::Key key) { return PrivacyString(session, key); } void AddPrivacyPremiumStar( not_null button, not_null<::Main::Session*> session, rpl::producer label, const QMargins &padding) { const auto badge = Ui::CreateChild(button.get()); badge->showOn(Data::AmPremiumValue(session)); const auto sampleLeft = st::settingsColorSamplePadding.left(); const auto badgeLeft = padding.left() + sampleLeft; const auto factor = style::DevicePixelRatio(); const auto size = Size(st::settingsButtonNoIcon.style.font->ascent); auto starImage = QImage( size * factor, QImage::Format_ARGB32_Premultiplied); starImage.setDevicePixelRatio(factor); starImage.fill(Qt::transparent); { auto p = QPainter(&starImage); auto star = QSvgRenderer( Ui::Premium::ColorizedSvg(Ui::Premium::ButtonGradientStops())); star.render(&p, Rect(size)); } badge->resize(starImage.size() / style::DevicePixelRatio()); badge->paintRequest( ) | rpl::on_next([=, star = std::move(starImage)] { auto p = QPainter(badge); p.drawImage(0, 0, star); }, badge->lifetime()); rpl::combine( button->sizeValue(), std::move(label) ) | rpl::on_next([=](const QSize &s, const QString &) { if (s.isNull()) { return; } badge->moveToLeft( button->fullTextWidth() + badgeLeft, (s.height() - badge->height()) / 2); }, badge->lifetime()); } object_ptr ClearPaymentInfoBox(not_null<::Main::Session*> session) { return Box(ClearPaymentInfoBoxBuilder, session); } void SetupSensitiveContent( not_null controller, not_null container, rpl::producer<> updateTrigger, HighlightRegistry *highlights) { using namespace rpl::mappers; const auto wrap = container->add( object_ptr>( container, object_ptr(container))); const auto inner = wrap->entity(); Ui::AddSkip(inner); Ui::AddSubsectionTitle(inner, tr::lng_settings_sensitive_title()); const auto show = controller->uiShow(); const auto session = &controller->session(); const auto disable = inner->lifetime().make_state>(); std::move( updateTrigger ) | rpl::on_next([=] { session->api().sensitiveContent().reload(); }, container->lifetime()); const auto button = inner->add(object_ptr