tdesktop/Telegram/SourceFiles/settings/settings_privacy_security.cpp

743 lines
20 KiB
C++
Raw Normal View History

2018-09-05 19:05:49 +00:00
/*
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 "api/api_authorizations.h"
#include "api/api_self_destruct.h"
#include "api/api_sensitive_content.h"
2020-07-03 16:53:24 +00:00
#include "api/api_global_privacy.h"
2018-09-05 19:05:49 +00:00
#include "settings/settings_common.h"
2018-09-11 19:00:23 +00:00
#include "settings/settings_privacy_controllers.h"
#include "base/timer_rpl.h"
#include "boxes/peer_list_box.h"
#include "boxes/edit_privacy_box.h"
#include "boxes/passcode_box.h"
2018-12-06 15:47:28 +00:00
#include "boxes/auto_lock_box.h"
#include "boxes/sessions_box.h"
#include "boxes/confirm_box.h"
#include "boxes/self_destruction_box.h"
#include "core/application.h"
#include "core/core_settings.h"
2018-09-05 19:05:49 +00:00
#include "ui/wrap/vertical_layout.h"
#include "ui/wrap/slide_wrap.h"
2018-11-07 09:39:31 +00:00
#include "ui/wrap/fade_wrap.h"
#include "ui/widgets/shadow.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/buttons.h"
#include "calls/calls_instance.h"
#include "core/core_cloud_password.h"
#include "core/update_checker.h"
2020-10-29 19:56:13 +00:00
#include "base/platform/base_platform_last_input.h"
2018-09-05 19:05:49 +00:00
#include "lang/lang_keys.h"
#include "data/data_session.h"
2019-05-20 18:40:53 +00:00
#include "data/data_chat.h"
#include "data/data_channel.h"
2019-07-24 11:45:24 +00:00
#include "main/main_session.h"
2019-07-24 14:00:30 +00:00
#include "window/window_session_controller.h"
#include "apiwrap.h"
#include "facades.h"
2018-09-05 19:05:49 +00:00
#include "styles/style_settings.h"
2018-11-07 09:39:31 +00:00
#include "styles/style_boxes.h"
2018-09-05 19:05:49 +00:00
2019-09-04 07:19:15 +00:00
#include <QtGui/QGuiApplication>
2018-09-05 19:05:49 +00:00
namespace Settings {
namespace {
constexpr auto kUpdateTimeout = 60 * crl::time(1000);
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) {
2019-06-19 15:09:03 +00:00
using Key = Privacy::Key;
using Option = Privacy::Option;
switch (key) {
case Key::CallsPeer2Peer:
switch (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);
}
Unexpected("Value in Privacy::Option.");
default:
switch (option) {
case Option::Everyone: return tr::lng_edit_privacy_everyone(tr::now);
case Option::Contacts: return tr::lng_edit_privacy_contacts(tr::now);
case Option::Nobody: return tr::lng_edit_privacy_nobody(tr::now);
}
2019-06-19 15:09:03 +00:00
Unexpected("Value in Privacy::Option.");
}
}
2019-07-24 14:00:30 +00:00
rpl::producer<QString> PrivacyString(
not_null<::Main::Session*> session,
Privacy::Key key) {
session->api().reloadPrivacy(key);
return session->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<int> BlockedPeersCount(not_null<::Main::Session*> session) {
return session->api().blockedPeersSlice(
) | rpl::map([=](const ApiWrap::BlockedPeersSlice &data) {
return data.total;
});
}
2019-07-24 14:00:30 +00:00
void SetupPrivacy(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container,
rpl::producer<> updateTrigger) {
AddSkip(container, st::settingsPrivacySkip);
2019-06-18 12:16:43 +00:00
AddSubsectionTitle(container, tr::lng_settings_privacy_title());
2019-07-24 14:00:30 +00:00
const auto session = &controller->session();
2019-07-15 08:58:43 +00:00
auto count = rpl::combine(
BlockedPeersCount(session),
2019-07-15 08:58:43 +00:00
tr::lng_settings_no_blocked_users()
) | rpl::map([](int count, const QString &none) {
return count ? QString::number(count) : none;
});
const auto blockedPeers = AddButtonWithLabel(
container,
2019-06-18 12:16:43 +00:00
tr::lng_settings_blocked_users(),
std::move(count),
st::settingsButton);
blockedPeers->addClickHandler([=] {
2019-07-24 14:00:30 +00:00
const auto initBox = [=](not_null<PeerListBox*> box) {
box->addButton(tr::lng_close(), [=] {
box->closeBox();
});
2019-07-24 14:00:30 +00:00
box->addLeftButton(tr::lng_blocked_list_add(), [=] {
BlockedBoxController::BlockNewPeer(controller);
});
};
Ui::show(Box<PeerListBox>(
2019-07-24 14:00:30 +00:00
std::make_unique<BlockedBoxController>(controller),
initBox));
});
std::move(
updateTrigger
) | rpl::start_with_next([=] {
session->api().reloadBlockedPeers();
}, blockedPeers->lifetime());
using Key = Privacy::Key;
2019-06-18 12:16:43 +00:00
const auto add = [&](
rpl::producer<QString> label,
Key key,
2019-07-24 14:00:30 +00:00
auto controllerFactory) {
AddPrivacyButton(
controller,
container,
std::move(label),
key,
controllerFactory);
};
add(
2019-06-18 12:16:43 +00:00
tr::lng_settings_phone_number_privacy(),
Key::PhoneNumber,
[] { return std::make_unique<PhoneNumberPrivacyController>(); });
add(
2019-06-18 12:16:43 +00:00
tr::lng_settings_last_seen(),
Key::LastSeen,
2019-07-24 14:00:30 +00:00
[=] { return std::make_unique<LastSeenPrivacyController>(session); });
add(
2019-06-18 12:16:43 +00:00
tr::lng_settings_forwards_privacy(),
Key::Forwards,
2020-06-10 18:08:17 +00:00
[=] { return std::make_unique<ForwardsPrivacyController>(controller); });
add(
2019-06-18 12:16:43 +00:00
tr::lng_settings_profile_photo_privacy(),
Key::ProfilePhoto,
[] { return std::make_unique<ProfilePhotoPrivacyController>(); });
add(
2019-06-18 12:16:43 +00:00
tr::lng_settings_calls(),
Key::Calls,
[] { return std::make_unique<CallsPrivacyController>(); });
add(
2019-06-18 12:16:43 +00:00
tr::lng_settings_groups_invite(),
Key::Invites,
[] { return std::make_unique<GroupsInvitePrivacyController>(); });
2019-08-29 08:44:03 +00:00
session->api().reloadPrivacy(ApiWrap::Privacy::Key::AddedByPhone);
AddSkip(container, st::settingsPrivacySecurityPadding);
2019-06-18 12:16:43 +00:00
AddDividerText(container, tr::lng_settings_group_privacy_about());
}
2020-07-03 16:53:24 +00:00
void SetupArchiveAndMute(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
using namespace rpl::mappers;
const auto wrap = container->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container)));
const auto inner = wrap->entity();
AddSkip(inner);
AddSubsectionTitle(inner, tr::lng_settings_new_unknown());
const auto session = &controller->session();
const auto privacy = &session->api().globalPrivacy();
privacy->reload();
AddButton(
inner,
tr::lng_settings_auto_archive(),
st::settingsButton
)->toggleOn(
privacy->archiveAndMute()
)->toggledChanges(
) | rpl::filter([=](bool toggled) {
return toggled != privacy->archiveAndMuteCurrent();
}) | rpl::start_with_next([=](bool toggled) {
privacy->update(toggled);
}, container->lifetime());
AddSkip(inner);
AddDividerText(inner, tr::lng_settings_auto_archive_about());
using namespace rpl::mappers;
wrap->toggleOn(rpl::single(
false
) | rpl::then(
session->api().globalPrivacy().showArchiveAndMute(
) | rpl::filter(_1) | rpl::take(1)
));
}
not_null<Ui::SlideWrap<Ui::PlainShadow>*> AddSeparator(
not_null<Ui::VerticalLayout*> container) {
return container->add(
object_ptr<Ui::SlideWrap<Ui::PlainShadow>>(
container,
object_ptr<Ui::PlainShadow>(container),
st::settingsSeparatorPadding));
}
2019-07-24 14:00:30 +00:00
void SetupLocalPasscode(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
AddSkip(container);
2019-06-18 12:16:43 +00:00
AddSubsectionTitle(container, tr::lng_settings_passcode_title());
auto has = PasscodeChanges(
) | rpl::map([] {
return Global::LocalPasscode();
});
auto text = rpl::combine(
2019-06-18 12:16:43 +00:00
tr::lng_passcode_change(),
tr::lng_passcode_turn_on(),
base::duplicate(has),
[](const QString &change, const QString &create, bool has) {
return has ? change : create;
});
container->add(
object_ptr<Button>(
container,
std::move(text),
2018-09-17 10:52:34 +00:00
st::settingsButton)
2019-07-24 14:00:30 +00:00
)->addClickHandler([=] {
Ui::show(Box<PasscodeBox>(&controller->session(), false));
});
const auto wrap = container->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container)));
const auto inner = wrap->entity();
inner->add(
object_ptr<Button>(
inner,
2019-06-18 12:16:43 +00:00
tr::lng_settings_passcode_disable(),
2018-09-17 10:52:34 +00:00
st::settingsButton)
2019-07-24 14:00:30 +00:00
)->addClickHandler([=] {
Ui::show(Box<PasscodeBox>(&controller->session(), true));
});
2020-10-29 19:56:13 +00:00
const auto label = base::Platform::LastUserInputTimeSupported()
2019-06-18 12:16:43 +00:00
? tr::lng_passcode_autolock_away
: tr::lng_passcode_autolock_inactive;
auto value = PasscodeChanges(
) | rpl::map([] {
const auto autolock = Core::App().settings().autoLock();
return (autolock % 3600)
? tr::lng_passcode_autolock_minutes(tr::now, lt_count, autolock / 60)
: tr::lng_passcode_autolock_hours(tr::now, lt_count, autolock / 3600);
});
2018-09-17 10:52:34 +00:00
AddButtonWithLabel(
inner,
2019-06-18 12:16:43 +00:00
label(),
2018-09-17 10:52:34 +00:00
std::move(value),
st::settingsButton
2019-07-24 14:00:30 +00:00
)->addClickHandler([=] {
Ui::show(Box<AutoLockBox>(&controller->session()));
});
wrap->toggleOn(base::duplicate(has));
AddSkip(container);
}
2019-07-24 14:00:30 +00:00
void SetupCloudPassword(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
2018-11-07 09:39:31 +00:00
using namespace rpl::mappers;
using State = Core::CloudPasswordState;
AddDivider(container);
AddSkip(container);
2019-06-18 12:16:43 +00:00
AddSubsectionTitle(container, tr::lng_settings_password_title());
2019-07-24 14:00:30 +00:00
const auto session = &controller->session();
auto has = rpl::single(
false
2019-07-24 14:00:30 +00:00
) | rpl::then(controller->session().api().passwordState(
) | rpl::map([](const State &state) {
return state.request
|| state.unknownAlgorithm
|| !state.unconfirmedPattern.isEmpty();
})) | rpl::distinct_until_changed();
2019-07-24 14:00:30 +00:00
auto pattern = session->api().passwordState(
) | rpl::map([](const State &state) {
return state.unconfirmedPattern;
});
auto confirmation = rpl::single(
2019-06-19 15:09:03 +00:00
tr::lng_profile_loading(tr::now)
) | rpl::then(rpl::duplicate(
pattern
) | rpl::filter([](const QString &pattern) {
return !pattern.isEmpty();
}) | rpl::map([](const QString &pattern) {
return tr::lng_cloud_password_waiting_code(tr::now, lt_email, pattern);
}));
auto unconfirmed = rpl::duplicate(
pattern
) | rpl::map([](const QString &pattern) {
return !pattern.isEmpty();
});
auto noconfirmed = rpl::single(
true
) | rpl::then(rpl::duplicate(
unconfirmed
));
const auto label = container->add(
object_ptr<Ui::SlideWrap<Ui::FlatLabel>>(
container,
object_ptr<Ui::FlatLabel>(
container,
base::duplicate(confirmation),
st::settingsCloudPasswordLabel),
QMargins(
2018-09-17 10:52:34 +00:00
st::settingsButton.padding.left(),
st::settingsButton.padding.top(),
st::settingsButton.padding.right(),
(st::settingsButton.height
- st::settingsCloudPasswordLabel.style.font->height
2018-09-17 10:52:34 +00:00
+ st::settingsButton.padding.bottom()))));
label->toggleOn(base::duplicate(noconfirmed))->setDuration(0);
std::move(
confirmation
) | rpl::start_with_next([=] {
container->resizeToWidth(container->width());
}, label->lifetime());
auto text = rpl::combine(
2019-06-18 12:16:43 +00:00
tr::lng_cloud_password_set(),
tr::lng_cloud_password_edit(),
base::duplicate(has)
) | rpl::map([](const QString &set, const QString &edit, bool has) {
return has ? edit : set;
});
const auto change = container->add(
object_ptr<Ui::SlideWrap<Button>>(
container,
object_ptr<Button>(
container,
std::move(text),
2018-09-17 10:52:34 +00:00
st::settingsButton)));
2018-11-07 09:39:31 +00:00
change->toggleOn(rpl::duplicate(
noconfirmed
) | rpl::map(
!_1
))->setDuration(0);
2019-07-24 14:00:30 +00:00
change->entity()->addClickHandler([=] {
if (CheckEditCloudPassword(session)) {
Ui::show(EditCloudPasswordBox(session));
} else {
Ui::show(CloudPasswordAppOutdatedBox());
}
});
2018-11-07 09:39:31 +00:00
const auto confirm = container->add(
object_ptr<Ui::SlideWrap<Button>>(
container,
object_ptr<Button>(
container,
2019-06-18 12:16:43 +00:00
tr::lng_cloud_password_confirm(),
2018-09-17 10:52:34 +00:00
st::settingsButton)));
confirm->toggleOn(rpl::single(
false
) | rpl::then(rpl::duplicate(
2018-11-07 09:39:31 +00:00
unconfirmed
)))->setDuration(0);
2019-07-24 14:00:30 +00:00
confirm->entity()->addClickHandler([=] {
const auto state = session->api().passwordStateCurrent();
if (!state) {
return;
}
auto validation = ConfirmRecoveryEmail(
&controller->session(),
state->unconfirmedPattern);
2018-11-07 09:39:31 +00:00
std::move(
validation.reloadRequests
2019-07-24 14:00:30 +00:00
) | rpl::start_with_next([=] {
session->api().reloadPasswordState();
2018-11-07 09:39:31 +00:00
}, validation.box->lifetime());
std::move(
validation.cancelRequests
2019-07-24 14:00:30 +00:00
) | rpl::start_with_next([=] {
session->api().clearUnconfirmedPassword();
2018-11-07 09:39:31 +00:00
}, validation.box->lifetime());
Ui::show(std::move(validation.box));
});
2019-07-24 14:00:30 +00:00
const auto remove = [=] {
if (CheckEditCloudPassword(session)) {
RemoveCloudPassword(session);
} else {
Ui::show(CloudPasswordAppOutdatedBox());
}
2018-11-07 09:39:31 +00:00
};
const auto disable = container->add(
object_ptr<Ui::SlideWrap<Button>>(
container,
object_ptr<Button>(
container,
2019-06-18 12:16:43 +00:00
tr::lng_settings_password_disable(),
2018-11-07 09:39:31 +00:00
st::settingsButton)));
disable->toggleOn(rpl::combine(
rpl::duplicate(has),
rpl::duplicate(noconfirmed),
2018-11-07 09:39:31 +00:00
_1 && !_2));
disable->entity()->addClickHandler(remove);
const auto abort = container->add(
object_ptr<Ui::SlideWrap<Button>>(
container,
object_ptr<Button>(
container,
2019-06-18 12:16:43 +00:00
tr::lng_settings_password_abort(),
2018-11-07 09:39:31 +00:00
st::settingsAttentionButton)));
abort->toggleOn(rpl::combine(
rpl::duplicate(has),
rpl::duplicate(noconfirmed),
2018-11-07 09:39:31 +00:00
_1 && _2));
abort->entity()->addClickHandler(remove);
const auto reloadOnActivation = [=](Qt::ApplicationState state) {
if (label->toggled() && state == Qt::ApplicationActive) {
2019-07-24 14:00:30 +00:00
controller->session().api().reloadPasswordState();
}
};
QObject::connect(
static_cast<QGuiApplication*>(QCoreApplication::instance()),
&QGuiApplication::applicationStateChanged,
label,
reloadOnActivation);
2019-07-24 14:00:30 +00:00
session->api().reloadPasswordState();
AddSkip(container);
AddDivider(container);
}
void SetupSensitiveContent(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container,
rpl::producer<> updateTrigger) {
using namespace rpl::mappers;
const auto wrap = container->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container)));
const auto inner = wrap->entity();
AddSkip(inner);
AddSubsectionTitle(inner, tr::lng_settings_sensitive_title());
const auto session = &controller->session();
std::move(
updateTrigger
) | rpl::start_with_next([=] {
session->api().sensitiveContent().reload();
}, container->lifetime());
AddButton(
inner,
tr::lng_settings_sensitive_disable_filtering(),
st::settingsButton
)->toggleOn(
session->api().sensitiveContent().enabled()
)->toggledChanges(
) | rpl::filter([=](bool toggled) {
return toggled != session->api().sensitiveContent().enabledCurrent();
}) | rpl::start_with_next([=](bool toggled) {
session->api().sensitiveContent().update(toggled);
}, container->lifetime());
AddSkip(inner);
AddDividerText(inner, tr::lng_settings_sensitive_about());
wrap->toggleOn(session->api().sensitiveContent().canChange());
}
2019-07-24 14:00:30 +00:00
void SetupSelfDestruction(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container,
rpl::producer<> updateTrigger) {
AddSkip(container);
2019-06-18 12:16:43 +00:00
AddSubsectionTitle(container, tr::lng_settings_destroy_title());
2019-07-24 14:00:30 +00:00
const auto session = &controller->session();
std::move(
updateTrigger
) | rpl::start_with_next([=] {
session->api().selfDestruct().reload();
}, container->lifetime());
2019-07-24 14:00:30 +00:00
const auto label = [&] {
return session->api().selfDestruct().days(
2018-09-17 17:31:01 +00:00
) | rpl::map(
SelfDestructionBox::DaysLabel
);
};
AddButtonWithLabel(
container,
2019-06-18 12:16:43 +00:00
tr::lng_settings_destroy_if(),
2018-09-17 17:31:01 +00:00
label(),
2018-09-17 10:52:34 +00:00
st::settingsButton
2019-07-24 14:00:30 +00:00
)->addClickHandler([=] {
2019-07-25 18:55:11 +00:00
Ui::show(Box<SelfDestructionBox>(
session,
session->api().selfDestruct().days()));
});
AddSkip(container);
}
2019-07-24 14:00:30 +00:00
void SetupSessionsList(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container,
rpl::producer<> updateTrigger) {
AddSkip(container);
2019-06-18 12:16:43 +00:00
AddSubsectionTitle(container, tr::lng_settings_sessions_title());
std::move(
updateTrigger
) | rpl::start_with_next([=] {
controller->session().api().authorizations().reload();
}, container->lifetime());
auto count = controller->session().api().authorizations().totalChanges(
) | rpl::map([](int count) {
return count ? QString::number(count) : QString();
});
AddButtonWithLabel(
container,
2019-06-18 12:16:43 +00:00
tr::lng_settings_show_sessions(),
std::move(count),
2018-09-17 10:52:34 +00:00
st::settingsButton
2019-07-25 18:55:11 +00:00
)->addClickHandler([=] {
Ui::show(Box<SessionsBox>(&controller->session()));
});
AddSkip(container, st::settingsPrivacySecurityPadding);
2019-06-18 12:16:43 +00:00
AddDividerText(container, tr::lng_settings_sessions_about());
}
} // namespace
2018-09-05 19:05:49 +00:00
2019-05-20 18:40:53 +00:00
int ExceptionUsersCount(const std::vector<not_null<PeerData*>> &exceptions) {
const auto add = [](int already, not_null<PeerData*> peer) {
if (const auto chat = peer->asChat()) {
return already + chat->count;
} else if (const auto channel = peer->asChannel()) {
return already + channel->membersCount();
}
return already + 1;
};
return ranges::accumulate(exceptions, 0, add);
}
2019-07-24 14:00:30 +00:00
bool CheckEditCloudPassword(not_null<::Main::Session*> session) {
const auto current = session->api().passwordStateCurrent();
Assert(current.has_value());
if (!current->unknownAlgorithm
&& !v::is_null(current->newPassword)
&& !v::is_null(current->newSecureSecret)) {
return true;
}
return false;
}
2019-09-18 11:19:05 +00:00
object_ptr<Ui::BoxContent> EditCloudPasswordBox(not_null<Main::Session*> session) {
const auto current = session->api().passwordStateCurrent();
Assert(current.has_value());
2019-07-24 14:00:30 +00:00
auto result = Box<PasscodeBox>(
session,
PasscodeBox::CloudFields::From(*current));
const auto box = result.data();
rpl::merge(
box->newPasswordSet() | rpl::to_empty,
box->passwordReloadNeeded()
) | rpl::start_with_next([=] {
session->api().reloadPasswordState();
}, box->lifetime());
box->clearUnconfirmedPassword(
) | rpl::start_with_next([=] {
session->api().clearUnconfirmedPassword();
}, box->lifetime());
return result;
}
2019-07-24 14:00:30 +00:00
void RemoveCloudPassword(not_null<::Main::Session*> session) {
const auto current = session->api().passwordStateCurrent();
Assert(current.has_value());
if (!current->request) {
2019-07-24 14:00:30 +00:00
session->api().clearUnconfirmedPassword();
return;
}
auto fields = PasscodeBox::CloudFields::From(*current);
fields.turningOff = true;
2019-07-24 14:00:30 +00:00
const auto box = Ui::show(Box<PasscodeBox>(session, fields));
rpl::merge(
box->newPasswordSet() | rpl::to_empty,
box->passwordReloadNeeded()
) | rpl::start_with_next([=] {
2019-07-24 14:00:30 +00:00
session->api().reloadPasswordState();
}, box->lifetime());
box->clearUnconfirmedPassword(
) | rpl::start_with_next([=] {
2019-07-24 14:00:30 +00:00
session->api().clearUnconfirmedPassword();
}, box->lifetime());
}
2019-09-18 11:19:05 +00:00
object_ptr<Ui::BoxContent> CloudPasswordAppOutdatedBox() {
const auto callback = [=](Fn<void()> &&close) {
Core::UpdateApplication();
close();
};
return Box<ConfirmBox>(
2019-06-19 15:09:03 +00:00
tr::lng_passport_app_out_of_date(tr::now),
tr::lng_menu_update(tr::now),
callback);
}
void AddPrivacyButton(
2019-07-24 14:00:30 +00:00
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container,
2019-06-18 12:16:43 +00:00
rpl::producer<QString> label,
Privacy::Key key,
2019-07-24 14:00:30 +00:00
Fn<std::unique_ptr<EditPrivacyController>()> controllerFactory) {
const auto shower = Ui::CreateChild<rpl::lifetime>(container.get());
2019-07-24 14:00:30 +00:00
const auto session = &controller->session();
AddButtonWithLabel(
container,
2019-06-18 12:16:43 +00:00
std::move(label),
2019-07-24 14:00:30 +00:00
PrivacyString(session, key),
st::settingsButton
)->addClickHandler([=] {
2019-07-24 14:00:30 +00:00
*shower = session->api().privacyValue(
key
) | rpl::take(
1
) | rpl::start_with_next([=](const Privacy &value) {
Ui::show(
2019-07-24 14:00:30 +00:00
Box<EditPrivacyBox>(controller, controllerFactory(), value),
2019-09-18 11:19:05 +00:00
Ui::LayerOption::KeepOther);
});
});
}
2019-07-24 14:00:30 +00:00
PrivacySecurity::PrivacySecurity(
QWidget *parent,
not_null<Window::SessionController*> controller)
: Section(parent) {
setupContent(controller);
2018-09-05 19:05:49 +00:00
}
2019-07-24 14:00:30 +00:00
void PrivacySecurity::setupContent(
not_null<Window::SessionController*> controller) {
2018-09-05 19:05:49 +00:00
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
auto updateOnTick = rpl::single(
) | rpl::then(base::timer_each(kUpdateTimeout));
const auto trigger = [=] {
return rpl::duplicate(updateOnTick);
};
SetupPrivacy(controller, content, trigger());
2020-07-03 16:53:24 +00:00
SetupArchiveAndMute(controller, content);
SetupSessionsList(controller, content, trigger());
2019-07-24 14:00:30 +00:00
SetupLocalPasscode(controller, content);
SetupCloudPassword(controller, content);
#if !defined OS_MAC_STORE && !defined OS_WIN_STORE
SetupSensitiveContent(controller, content, trigger());
#else // !OS_MAC_STORE && !OS_WIN_STORE
AddDivider(content);
#endif // !OS_MAC_STORE && !OS_WIN_STORE
SetupSelfDestruction(controller, content, trigger());
2018-09-05 19:05:49 +00:00
Ui::ResizeFitChild(this, content);
}
} // namespace Settings