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"
|
|
|
|
|
2020-09-08 15:38:36 +00:00
|
|
|
#include "api/api_authorizations.h"
|
2021-08-01 22:57:36 +00:00
|
|
|
#include "api/api_blocked_peers.h"
|
2021-08-02 19:06:33 +00:00
|
|
|
#include "api/api_cloud_password.h"
|
2019-12-09 12:59:08 +00:00
|
|
|
#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"
|
2020-09-12 14:10:56 +00:00
|
|
|
#include "base/timer_rpl.h"
|
2021-07-30 11:32:49 +00:00
|
|
|
#include "base/unixtime.h"
|
2018-09-09 12:10:54 +00:00
|
|
|
#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"
|
2018-09-09 12:10:54 +00:00
|
|
|
#include "boxes/sessions_box.h"
|
2021-10-18 21:36:55 +00:00
|
|
|
#include "ui/boxes/confirm_box.h"
|
2018-09-09 12:10:54 +00:00
|
|
|
#include "boxes/self_destruction_box.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/core_settings.h"
|
2021-08-28 05:51:39 +00:00
|
|
|
#include "ui/chat/chat_style.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2018-09-09 12:10:54 +00:00
|
|
|
#include "ui/wrap/slide_wrap.h"
|
2018-11-07 09:39:31 +00:00
|
|
|
#include "ui/wrap/fade_wrap.h"
|
2018-09-09 12:10:54 +00:00
|
|
|
#include "ui/widgets/shadow.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
2019-11-02 17:06:47 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2021-04-07 11:43:32 +00:00
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/layers/generic_box.h"
|
2018-09-12 17:02:30 +00:00
|
|
|
#include "calls/calls_instance.h"
|
2018-09-09 12:10:54 +00:00
|
|
|
#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"
|
2018-09-09 12:10:54 +00:00
|
|
|
#include "data/data_session.h"
|
2019-05-20 18:40:53 +00:00
|
|
|
#include "data/data_chat.h"
|
|
|
|
#include "data/data_channel.h"
|
2021-05-25 20:38:01 +00:00
|
|
|
#include "main/main_domain.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2021-05-25 20:38:01 +00:00
|
|
|
#include "storage/storage_domain.h"
|
2019-07-24 14:00:30 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2018-09-09 12:10:54 +00:00
|
|
|
#include "apiwrap.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
#include "styles/style_settings.h"
|
2021-04-07 11:43:32 +00:00
|
|
|
#include "styles/style_layers.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 {
|
2018-09-09 12:10:54 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-09-12 14:10:56 +00:00
|
|
|
constexpr auto kUpdateTimeout = 60 * crl::time(1000);
|
|
|
|
|
2021-07-31 14:11:53 +00:00
|
|
|
using Privacy = Api::UserPrivacy;
|
2019-05-21 12:51:24 +00:00
|
|
|
|
|
|
|
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);
|
2018-09-12 17:02:30 +00:00
|
|
|
}
|
2019-06-19 15:09:03 +00:00
|
|
|
Unexpected("Value in Privacy::Option.");
|
|
|
|
}
|
2018-09-12 17:02:30 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
rpl::producer<QString> PrivacyString(
|
|
|
|
not_null<::Main::Session*> session,
|
|
|
|
Privacy::Key key) {
|
2021-07-31 14:11:53 +00:00
|
|
|
session->api().userPrivacy().reload(key);
|
|
|
|
return session->api().userPrivacy().value(
|
2019-05-21 12:51:24 +00:00
|
|
|
key
|
2021-07-31 14:11:53 +00:00
|
|
|
) | rpl::map([=](const Privacy::Rule &value) {
|
2019-05-21 12:51:24 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-01 06:44:18 +00:00
|
|
|
rpl::producer<int> BlockedPeersCount(not_null<::Main::Session*> session) {
|
2021-08-01 22:57:36 +00:00
|
|
|
return session->api().blockedPeers().slice(
|
|
|
|
) | rpl::map([](const Api::BlockedPeers::Slice &data) {
|
2019-05-24 13:06:17 +00:00
|
|
|
return data.total;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupPrivacy(
|
|
|
|
not_null<Window::SessionController*> controller,
|
2020-09-12 14:10:56 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<> updateTrigger) {
|
2018-09-15 10:37:48 +00:00
|
|
|
AddSkip(container, st::settingsPrivacySkip);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(container, tr::lng_settings_privacy_title());
|
2018-09-15 10:37:48 +00:00
|
|
|
|
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(
|
2020-09-01 06:44:18 +00:00
|
|
|
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;
|
2019-05-24 13:06:17 +00:00
|
|
|
});
|
2020-09-12 14:10:56 +00:00
|
|
|
const auto blockedPeers = AddButtonWithLabel(
|
2018-09-09 12:10:54 +00:00
|
|
|
container,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_blocked_users(),
|
2019-05-24 13:06:17 +00:00
|
|
|
std::move(count),
|
2020-09-12 14:10:56 +00:00
|
|
|
st::settingsButton);
|
|
|
|
blockedPeers->addClickHandler([=] {
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto initBox = [=](not_null<PeerListBox*> box) {
|
2019-06-18 16:53:27 +00:00
|
|
|
box->addButton(tr::lng_close(), [=] {
|
2018-09-09 12:10:54 +00:00
|
|
|
box->closeBox();
|
|
|
|
});
|
2019-07-24 14:00:30 +00:00
|
|
|
box->addLeftButton(tr::lng_blocked_list_add(), [=] {
|
2020-09-01 06:44:18 +00:00
|
|
|
BlockedBoxController::BlockNewPeer(controller);
|
2018-09-09 12:10:54 +00:00
|
|
|
});
|
|
|
|
};
|
2021-06-13 07:37:52 +00:00
|
|
|
controller->show(Box<PeerListBox>(
|
2019-07-24 14:00:30 +00:00
|
|
|
std::make_unique<BlockedBoxController>(controller),
|
2018-09-09 12:10:54 +00:00
|
|
|
initBox));
|
|
|
|
});
|
2020-09-12 14:10:56 +00:00
|
|
|
std::move(
|
|
|
|
updateTrigger
|
|
|
|
) | rpl::start_with_next([=] {
|
2021-08-01 22:57:36 +00:00
|
|
|
session->api().blockedPeers().reload();
|
2020-09-12 14:10:56 +00:00
|
|
|
}, blockedPeers->lifetime());
|
2018-09-09 12:10:54 +00:00
|
|
|
|
2019-05-21 12:51:24 +00:00
|
|
|
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);
|
2018-09-11 09:11:52 +00:00
|
|
|
};
|
2019-05-21 12:51:24 +00:00
|
|
|
add(
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_phone_number_privacy(),
|
2019-05-21 12:51:24 +00:00
|
|
|
Key::PhoneNumber,
|
|
|
|
[] { return std::make_unique<PhoneNumberPrivacyController>(); });
|
2018-09-11 09:11:52 +00:00
|
|
|
add(
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_last_seen(),
|
2019-05-21 12:51:24 +00:00
|
|
|
Key::LastSeen,
|
2019-07-24 14:00:30 +00:00
|
|
|
[=] { return std::make_unique<LastSeenPrivacyController>(session); });
|
2019-03-19 10:39:19 +00:00
|
|
|
add(
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_forwards_privacy(),
|
2019-05-21 12:51:24 +00:00
|
|
|
Key::Forwards,
|
2021-07-02 15:29:13 +00:00
|
|
|
[=] { return std::make_unique<ForwardsPrivacyController>(
|
|
|
|
controller); });
|
2019-03-19 10:39:19 +00:00
|
|
|
add(
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_profile_photo_privacy(),
|
2019-05-21 12:51:24 +00:00
|
|
|
Key::ProfilePhoto,
|
2019-03-19 10:39:19 +00:00
|
|
|
[] { return std::make_unique<ProfilePhotoPrivacyController>(); });
|
2018-09-11 09:11:52 +00:00
|
|
|
add(
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_calls(),
|
2019-05-21 12:51:24 +00:00
|
|
|
Key::Calls,
|
2018-09-11 09:11:52 +00:00
|
|
|
[] { return std::make_unique<CallsPrivacyController>(); });
|
|
|
|
add(
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_groups_invite(),
|
2019-05-21 12:51:24 +00:00
|
|
|
Key::Invites,
|
2018-09-11 09:11:52 +00:00
|
|
|
[] { return std::make_unique<GroupsInvitePrivacyController>(); });
|
2018-09-09 12:10:54 +00:00
|
|
|
|
2021-07-31 14:11:53 +00:00
|
|
|
session->api().userPrivacy().reload(Api::UserPrivacy::Key::AddedByPhone);
|
2019-08-29 08:44:03 +00:00
|
|
|
|
2018-09-10 12:18:39 +00:00
|
|
|
AddSkip(container, st::settingsPrivacySecurityPadding);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddDividerText(container, tr::lng_settings_group_privacy_about());
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupLocalPasscode(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
2018-09-15 10:37:48 +00:00
|
|
|
AddSkip(container);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(container, tr::lng_settings_passcode_title());
|
2018-09-15 10:37:48 +00:00
|
|
|
|
2021-05-25 20:38:01 +00:00
|
|
|
auto has = rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(
|
|
|
|
controller->session().domain().local().localPasscodeChanged()
|
|
|
|
) | rpl::map([=] {
|
|
|
|
return controller->session().domain().local().hasLocalPasscode();
|
2018-09-09 12:10:54 +00:00
|
|
|
});
|
|
|
|
auto text = rpl::combine(
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_passcode_change(),
|
|
|
|
tr::lng_passcode_turn_on(),
|
2018-09-09 12:10:54 +00:00
|
|
|
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([=] {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller->show(Box<PasscodeBox>(&controller->session(), false));
|
2018-09-09 12:10:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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([=] {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller->show(Box<PasscodeBox>(&controller->session(), true));
|
2018-09-09 12:10:54 +00:00
|
|
|
});
|
|
|
|
|
2021-05-25 18:31:01 +00:00
|
|
|
const auto autoLockBoxClosing =
|
|
|
|
container->lifetime().make_state<rpl::event_stream<>>();
|
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;
|
2021-05-25 18:31:01 +00:00
|
|
|
auto value = autoLockBoxClosing->events_starting_with(
|
|
|
|
rpl::empty_value()
|
2018-09-09 12:10:54 +00:00
|
|
|
) | rpl::map([] {
|
2020-06-18 18:04:16 +00:00
|
|
|
const auto autolock = Core::App().settings().autoLock();
|
2021-08-11 05:58:11 +00:00
|
|
|
const auto hours = autolock / 3600;
|
|
|
|
const auto minutes = (autolock - (hours * 3600)) / 60;
|
|
|
|
|
|
|
|
return (hours && minutes)
|
|
|
|
? tr::lng_passcode_autolock_hours_minutes(
|
|
|
|
tr::now,
|
|
|
|
lt_hours_count,
|
|
|
|
QString::number(hours),
|
|
|
|
lt_minutes_count,
|
|
|
|
QString::number(minutes))
|
|
|
|
: minutes
|
2021-05-25 18:31:01 +00:00
|
|
|
? tr::lng_passcode_autolock_minutes(
|
|
|
|
tr::now,
|
|
|
|
lt_count,
|
2021-08-11 05:58:11 +00:00
|
|
|
minutes)
|
2021-05-25 18:31:01 +00:00
|
|
|
: tr::lng_passcode_autolock_hours(
|
|
|
|
tr::now,
|
|
|
|
lt_count,
|
2021-08-11 05:58:11 +00:00
|
|
|
hours);
|
2018-09-09 12:10:54 +00:00
|
|
|
});
|
|
|
|
|
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([=] {
|
2021-08-11 05:58:11 +00:00
|
|
|
const auto box = controller->show(Box<AutoLockBox>());
|
2021-05-25 18:31:01 +00:00
|
|
|
box->boxClosing(
|
|
|
|
) | rpl::start_to_stream(*autoLockBoxClosing, box->lifetime());
|
2018-09-09 12:10:54 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
wrap->toggleOn(base::duplicate(has));
|
|
|
|
|
2018-09-15 10:37:48 +00:00
|
|
|
AddSkip(container);
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2018-09-15 10:37:48 +00:00
|
|
|
AddDivider(container);
|
|
|
|
AddSkip(container);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(container, tr::lng_settings_password_title());
|
2018-09-15 10:37:48 +00:00
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto session = &controller->session();
|
2018-09-09 12:10:54 +00:00
|
|
|
auto has = rpl::single(
|
|
|
|
false
|
2021-08-02 19:06:33 +00:00
|
|
|
) | rpl::then(controller->session().api().cloudPassword().state(
|
2018-09-09 12:10:54 +00:00
|
|
|
) | rpl::map([](const State &state) {
|
|
|
|
return state.request
|
|
|
|
|| state.unknownAlgorithm
|
|
|
|
|| !state.unconfirmedPattern.isEmpty();
|
|
|
|
})) | rpl::distinct_until_changed();
|
2021-08-02 19:06:33 +00:00
|
|
|
auto pattern = session->api().cloudPassword().state(
|
2018-09-09 12:10:54 +00:00
|
|
|
) | 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)
|
2018-12-25 10:52:53 +00:00
|
|
|
) | rpl::then(rpl::duplicate(
|
2018-09-09 12:10:54 +00:00
|
|
|
pattern
|
|
|
|
) | rpl::filter([](const QString &pattern) {
|
|
|
|
return !pattern.isEmpty();
|
|
|
|
}) | rpl::map([](const QString &pattern) {
|
2019-06-19 16:39:25 +00:00
|
|
|
return tr::lng_cloud_password_waiting_code(tr::now, lt_email, pattern);
|
2018-09-09 12:10:54 +00:00
|
|
|
}));
|
2018-12-25 10:52:53 +00:00
|
|
|
auto unconfirmed = rpl::duplicate(
|
2018-09-09 12:10:54 +00:00
|
|
|
pattern
|
|
|
|
) | rpl::map([](const QString &pattern) {
|
|
|
|
return !pattern.isEmpty();
|
2018-12-25 10:52:53 +00:00
|
|
|
});
|
|
|
|
auto noconfirmed = rpl::single(
|
|
|
|
true
|
|
|
|
) | rpl::then(rpl::duplicate(
|
|
|
|
unconfirmed
|
|
|
|
));
|
2021-08-02 19:06:33 +00:00
|
|
|
auto resetAt = session->api().cloudPassword().state(
|
2021-07-30 11:32:49 +00:00
|
|
|
) | rpl::map([](const State &state) {
|
|
|
|
return state.pendingResetDate;
|
|
|
|
});
|
2018-09-09 12:10:54 +00:00
|
|
|
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
|
2018-09-09 12:10:54 +00:00
|
|
|
- st::settingsCloudPasswordLabel.style.font->height
|
2018-09-17 10:52:34 +00:00
|
|
|
+ st::settingsButton.padding.bottom()))));
|
2018-12-25 10:52:53 +00:00
|
|
|
label->toggleOn(base::duplicate(noconfirmed))->setDuration(0);
|
2018-09-09 12:10:54 +00:00
|
|
|
|
|
|
|
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(),
|
2018-09-09 12:10:54 +00:00
|
|
|
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(
|
2018-12-25 10:52:53 +00:00
|
|
|
noconfirmed
|
|
|
|
) | rpl::map(
|
|
|
|
!_1
|
|
|
|
))->setDuration(0);
|
2019-07-24 14:00:30 +00:00
|
|
|
change->entity()->addClickHandler([=] {
|
|
|
|
if (CheckEditCloudPassword(session)) {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller->show(EditCloudPasswordBox(session));
|
2019-06-14 12:01:35 +00:00
|
|
|
} else {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller->show(CloudPasswordAppOutdatedBox());
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-07 09:39:31 +00:00
|
|
|
const auto confirm = container->add(
|
2018-09-09 12:10:54 +00:00
|
|
|
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)));
|
2018-12-25 10:52:53 +00:00
|
|
|
confirm->toggleOn(rpl::single(
|
|
|
|
false
|
|
|
|
) | rpl::then(rpl::duplicate(
|
2018-11-07 09:39:31 +00:00
|
|
|
unconfirmed
|
2018-12-25 10:52:53 +00:00
|
|
|
)))->setDuration(0);
|
2019-07-24 14:00:30 +00:00
|
|
|
confirm->entity()->addClickHandler([=] {
|
2021-08-02 19:06:33 +00:00
|
|
|
const auto state = session->api().cloudPassword().stateCurrent();
|
2018-12-25 10:52:53 +00:00
|
|
|
if (!state) {
|
|
|
|
return;
|
|
|
|
}
|
2020-06-11 16:09:46 +00:00
|
|
|
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([=] {
|
2021-08-02 19:06:33 +00:00
|
|
|
session->api().cloudPassword().reload();
|
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([=] {
|
2021-08-02 19:06:33 +00:00
|
|
|
session->api().cloudPassword().clearUnconfirmedPassword();
|
2018-11-07 09:39:31 +00:00
|
|
|
}, validation.box->lifetime());
|
|
|
|
|
2021-06-13 07:37:52 +00:00
|
|
|
controller->show(std::move(validation.box));
|
2018-11-07 09:39:31 +00:00
|
|
|
});
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto remove = [=] {
|
|
|
|
if (CheckEditCloudPassword(session)) {
|
2021-06-13 07:37:52 +00:00
|
|
|
RemoveCloudPassword(controller);
|
2019-06-14 12:01:35 +00:00
|
|
|
} else {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller->show(CloudPasswordAppOutdatedBox());
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
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),
|
2018-12-25 10:52:53 +00:00
|
|
|
rpl::duplicate(noconfirmed),
|
2018-11-07 09:39:31 +00:00
|
|
|
_1 && !_2));
|
|
|
|
disable->entity()->addClickHandler(remove);
|
|
|
|
|
2021-07-30 11:32:49 +00:00
|
|
|
auto resetInSeconds = rpl::duplicate(
|
|
|
|
resetAt
|
|
|
|
) | rpl::filter([](TimeId time) {
|
|
|
|
return time != 0;
|
|
|
|
}) | rpl::map([](TimeId time) {
|
|
|
|
return rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(base::timer_each(
|
|
|
|
999
|
|
|
|
)) | rpl::map([=] {
|
|
|
|
const auto now = base::unixtime::now();
|
|
|
|
return (time - now);
|
|
|
|
}) | rpl::distinct_until_changed(
|
|
|
|
) | rpl::take_while([](TimeId left) {
|
|
|
|
return left > 0;
|
|
|
|
}) | rpl::then(rpl::single(TimeId(0)));
|
|
|
|
}) | rpl::flatten_latest(
|
|
|
|
) | rpl::start_spawning(container->lifetime());
|
|
|
|
|
|
|
|
auto resetText = rpl::duplicate(
|
|
|
|
resetInSeconds
|
|
|
|
) | rpl::map([](TimeId left) {
|
|
|
|
return (left > 0);
|
|
|
|
}) | rpl::distinct_until_changed(
|
|
|
|
) | rpl::map([](bool waiting) {
|
|
|
|
return waiting
|
|
|
|
? tr::lng_cloud_password_reset_in()
|
|
|
|
: tr::lng_cloud_password_reset_ready();
|
|
|
|
}) | rpl::flatten_latest();
|
|
|
|
|
|
|
|
constexpr auto kMinute = 60;
|
|
|
|
constexpr auto kHour = 3600;
|
|
|
|
constexpr auto kDay = 86400;
|
|
|
|
auto resetLabel = rpl::duplicate(
|
|
|
|
resetInSeconds
|
|
|
|
) | rpl::map([](TimeId left) {
|
|
|
|
return (left >= kDay)
|
|
|
|
? ((left / kDay) * kDay)
|
|
|
|
: (left >= kHour)
|
|
|
|
? ((left / kHour) * kHour)
|
|
|
|
: (left >= kMinute)
|
|
|
|
? ((left / kMinute) * kMinute)
|
|
|
|
: left;
|
|
|
|
}) | rpl::distinct_until_changed(
|
|
|
|
) | rpl::map([](TimeId left) {
|
|
|
|
const auto days = left / kDay;
|
|
|
|
const auto hours = left / kHour;
|
|
|
|
const auto minutes = left / kMinute;
|
|
|
|
return days
|
|
|
|
? tr::lng_group_call_duration_days(tr::now, lt_count, days)
|
|
|
|
: hours
|
|
|
|
? tr::lng_group_call_duration_hours(tr::now, lt_count, hours)
|
|
|
|
: minutes
|
|
|
|
? tr::lng_group_call_duration_minutes(tr::now, lt_count, minutes)
|
|
|
|
: left
|
|
|
|
? tr::lng_group_call_duration_seconds(tr::now, lt_count, left)
|
|
|
|
: QString();
|
|
|
|
});
|
|
|
|
|
|
|
|
const auto reset = container->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Button>>(
|
|
|
|
container,
|
|
|
|
object_ptr<Button>(
|
|
|
|
container,
|
|
|
|
rpl::duplicate(resetText),
|
|
|
|
st::settingsButton))
|
|
|
|
)->setDuration(0);
|
|
|
|
CreateRightLabel(
|
|
|
|
reset->entity(),
|
|
|
|
std::move(resetLabel),
|
|
|
|
st::settingsButton,
|
|
|
|
std::move(resetText));
|
|
|
|
|
|
|
|
reset->toggleOn(rpl::duplicate(
|
|
|
|
resetAt
|
|
|
|
) | rpl::map([](TimeId time) {
|
|
|
|
return time != 0;
|
|
|
|
}));
|
2021-08-15 10:11:48 +00:00
|
|
|
const auto sent = std::make_shared<bool>(false);
|
2021-07-30 11:32:49 +00:00
|
|
|
reset->entity()->addClickHandler([=] {
|
|
|
|
const auto api = &session->api();
|
2021-08-02 19:06:33 +00:00
|
|
|
const auto state = api->cloudPassword().stateCurrent();
|
2021-07-30 11:32:49 +00:00
|
|
|
const auto date = state ? state->pendingResetDate : TimeId(0);
|
|
|
|
if (!date || *sent) {
|
|
|
|
return;
|
|
|
|
} else if (base::unixtime::now() >= date) {
|
2021-08-15 10:11:48 +00:00
|
|
|
*sent = true;
|
|
|
|
api->cloudPassword().resetPassword(
|
|
|
|
) | rpl::start_with_error_done([=](const QString &error) {
|
|
|
|
*sent = false;
|
|
|
|
}, [=] {
|
|
|
|
*sent = false;
|
|
|
|
}, container->lifetime());
|
2021-07-30 11:32:49 +00:00
|
|
|
} else {
|
|
|
|
const auto cancel = [=] {
|
|
|
|
Ui::hideLayer();
|
2021-08-15 10:11:48 +00:00
|
|
|
*sent = true;
|
|
|
|
api->cloudPassword().cancelResetPassword(
|
|
|
|
) | rpl::start_with_error_done([=](const QString &error) {
|
|
|
|
*sent = false;
|
|
|
|
}, [=] {
|
|
|
|
*sent = false;
|
|
|
|
}, container->lifetime());
|
2021-07-30 11:32:49 +00:00
|
|
|
};
|
2021-10-18 22:28:08 +00:00
|
|
|
Ui::show(Box<Ui::ConfirmBox>(
|
2021-07-30 11:32:49 +00:00
|
|
|
tr::lng_cloud_password_reset_cancel_sure(tr::now),
|
|
|
|
tr::lng_box_yes(tr::now),
|
|
|
|
tr::lng_box_no(tr::now),
|
|
|
|
cancel));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-07 09:39:31 +00:00
|
|
|
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),
|
2018-12-25 10:52:53 +00:00
|
|
|
rpl::duplicate(noconfirmed),
|
2018-11-07 09:39:31 +00:00
|
|
|
_1 && _2));
|
|
|
|
abort->entity()->addClickHandler(remove);
|
2018-09-09 12:10:54 +00:00
|
|
|
|
|
|
|
const auto reloadOnActivation = [=](Qt::ApplicationState state) {
|
|
|
|
if (label->toggled() && state == Qt::ApplicationActive) {
|
2021-08-02 19:06:33 +00:00
|
|
|
controller->session().api().cloudPassword().reload();
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
QObject::connect(
|
2019-01-21 13:42:21 +00:00
|
|
|
static_cast<QGuiApplication*>(QCoreApplication::instance()),
|
|
|
|
&QGuiApplication::applicationStateChanged,
|
2018-09-09 12:10:54 +00:00
|
|
|
label,
|
|
|
|
reloadOnActivation);
|
|
|
|
|
2021-08-02 19:06:33 +00:00
|
|
|
session->api().cloudPassword().reload();
|
2018-09-15 10:37:48 +00:00
|
|
|
|
|
|
|
AddSkip(container);
|
2019-12-09 12:59:08 +00:00
|
|
|
AddDivider(container);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupSensitiveContent(
|
|
|
|
not_null<Window::SessionController*> controller,
|
2020-09-12 14:10:56 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<> updateTrigger) {
|
2019-12-09 12:59:08 +00:00
|
|
|
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();
|
|
|
|
|
2020-09-12 14:10:56 +00:00
|
|
|
std::move(
|
|
|
|
updateTrigger
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
session->api().sensitiveContent().reload();
|
|
|
|
}, container->lifetime());
|
2019-12-09 12:59:08 +00:00
|
|
|
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());
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupSelfDestruction(
|
|
|
|
not_null<Window::SessionController*> controller,
|
2020-09-12 14:10:56 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<> updateTrigger) {
|
2018-09-15 10:37:48 +00:00
|
|
|
AddSkip(container);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(container, tr::lng_settings_destroy_title());
|
2018-09-15 10:37:48 +00:00
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto session = &controller->session();
|
|
|
|
|
2020-09-12 14:10:56 +00:00
|
|
|
std::move(
|
|
|
|
updateTrigger
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
session->api().selfDestruct().reload();
|
|
|
|
}, container->lifetime());
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto label = [&] {
|
2019-12-09 12:59:08 +00:00
|
|
|
return session->api().selfDestruct().days(
|
2018-09-17 17:31:01 +00:00
|
|
|
) | rpl::map(
|
|
|
|
SelfDestructionBox::DaysLabel
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
AddButtonWithLabel(
|
2018-09-09 12:10:54 +00:00
|
|
|
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([=] {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller->show(Box<SelfDestructionBox>(
|
2019-07-25 18:55:11 +00:00
|
|
|
session,
|
2021-11-25 20:52:06 +00:00
|
|
|
SelfDestructionBox::Type::Account,
|
2019-12-09 12:59:08 +00:00
|
|
|
session->api().selfDestruct().days()));
|
2018-09-09 12:10:54 +00:00
|
|
|
});
|
2018-09-15 10:37:48 +00:00
|
|
|
|
|
|
|
AddSkip(container);
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
2021-04-07 11:43:32 +00:00
|
|
|
void ClearPaymentInfoBoxBuilder(
|
|
|
|
not_null<Ui::GenericBox*> 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<Ui::FlatLabel>(
|
|
|
|
box,
|
|
|
|
tr::lng_clear_payment_info_sure(),
|
|
|
|
st::boxLabel));
|
|
|
|
const auto shipping = box->addRow(
|
|
|
|
object_ptr<Ui::Checkbox>(
|
|
|
|
box,
|
|
|
|
tr::lng_clear_payment_info_shipping(tr::now),
|
|
|
|
true,
|
|
|
|
st::defaultBoxCheckbox),
|
|
|
|
checkboxPadding);
|
|
|
|
const auto payment = box->addRow(
|
|
|
|
object_ptr<Ui::Checkbox>(
|
|
|
|
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<Flags>();
|
|
|
|
|
|
|
|
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<Ui::FlatLabel>(
|
|
|
|
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(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
auto ClearPaymentInfoBox(not_null<Main::Session*> session) {
|
|
|
|
return Box(ClearPaymentInfoBoxBuilder, session);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupBotsAndWebsites(
|
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
not_null<Ui::VerticalLayout*> container) {
|
|
|
|
AddSkip(container);
|
|
|
|
AddSubsectionTitle(container, tr::lng_settings_security_bots());
|
|
|
|
|
|
|
|
const auto session = &controller->session();
|
|
|
|
AddButton(
|
|
|
|
container,
|
|
|
|
tr::lng_settings_clear_payment_info(),
|
|
|
|
st::settingsButton
|
|
|
|
)->addClickHandler([=] {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller->show(ClearPaymentInfoBox(session));
|
2021-04-07 11:43:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddSkip(container);
|
|
|
|
}
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
void SetupSessionsList(
|
|
|
|
not_null<Window::SessionController*> controller,
|
2020-09-12 14:10:56 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2021-11-29 13:29:45 +00:00
|
|
|
rpl::producer<> updateTrigger,
|
|
|
|
Fn<void(Type)> showOther) {
|
2018-09-15 10:37:48 +00:00
|
|
|
AddSkip(container);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(container, tr::lng_settings_sessions_title());
|
2018-09-15 10:37:48 +00:00
|
|
|
|
2020-09-12 14:10:56 +00:00
|
|
|
std::move(
|
|
|
|
updateTrigger
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
controller->session().api().authorizations().reload();
|
|
|
|
}, container->lifetime());
|
2021-06-07 15:42:18 +00:00
|
|
|
|
2020-09-12 14:10:56 +00:00
|
|
|
auto count = controller->session().api().authorizations().totalChanges(
|
2020-09-08 15:38:36 +00:00
|
|
|
) | rpl::map([](int count) {
|
|
|
|
return count ? QString::number(count) : QString();
|
|
|
|
});
|
|
|
|
|
|
|
|
AddButtonWithLabel(
|
2018-09-09 12:10:54 +00:00
|
|
|
container,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_show_sessions(),
|
2020-09-08 15:38:36 +00:00
|
|
|
std::move(count),
|
2018-09-17 10:52:34 +00:00
|
|
|
st::settingsButton
|
2019-07-25 18:55:11 +00:00
|
|
|
)->addClickHandler([=] {
|
2021-11-29 13:29:45 +00:00
|
|
|
showOther(Type::Sessions);
|
2018-09-09 12:10:54 +00:00
|
|
|
});
|
2018-09-10 12:18:39 +00:00
|
|
|
AddSkip(container, st::settingsPrivacySecurityPadding);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddDividerText(container, tr::lng_settings_sessions_about());
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // 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) {
|
2021-08-02 19:06:33 +00:00
|
|
|
const auto current = session->api().cloudPassword().stateCurrent();
|
2019-06-14 12:01:35 +00:00
|
|
|
Assert(current.has_value());
|
|
|
|
|
|
|
|
if (!current->unknownAlgorithm
|
2020-08-31 09:04:17 +00:00
|
|
|
&& !v::is_null(current->newPassword)
|
|
|
|
&& !v::is_null(current->newSecureSecret)) {
|
2019-06-14 12:01:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
object_ptr<Ui::BoxContent> EditCloudPasswordBox(not_null<Main::Session*> session) {
|
2021-08-02 19:06:33 +00:00
|
|
|
const auto current = session->api().cloudPassword().stateCurrent();
|
2019-06-14 12:01:35 +00:00
|
|
|
Assert(current.has_value());
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
auto result = Box<PasscodeBox>(
|
|
|
|
session,
|
|
|
|
PasscodeBox::CloudFields::From(*current));
|
2019-06-14 12:01:35 +00:00
|
|
|
const auto box = result.data();
|
|
|
|
|
|
|
|
rpl::merge(
|
2020-06-21 16:25:29 +00:00
|
|
|
box->newPasswordSet() | rpl::to_empty,
|
2019-06-14 12:01:35 +00:00
|
|
|
box->passwordReloadNeeded()
|
|
|
|
) | rpl::start_with_next([=] {
|
2021-08-02 19:06:33 +00:00
|
|
|
session->api().cloudPassword().reload();
|
2019-06-14 12:01:35 +00:00
|
|
|
}, box->lifetime());
|
|
|
|
|
|
|
|
box->clearUnconfirmedPassword(
|
|
|
|
) | rpl::start_with_next([=] {
|
2021-08-02 19:06:33 +00:00
|
|
|
session->api().cloudPassword().clearUnconfirmedPassword();
|
2019-06-14 12:01:35 +00:00
|
|
|
}, box->lifetime());
|
|
|
|
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2019-06-14 12:01:35 +00:00
|
|
|
}
|
|
|
|
|
2021-06-13 07:37:52 +00:00
|
|
|
void RemoveCloudPassword(not_null<Window::SessionController*> controller) {
|
|
|
|
const auto session = &controller->session();
|
2021-08-02 19:06:33 +00:00
|
|
|
const auto current = session->api().cloudPassword().stateCurrent();
|
2019-06-14 12:01:35 +00:00
|
|
|
Assert(current.has_value());
|
|
|
|
|
|
|
|
if (!current->request) {
|
2021-08-02 19:06:33 +00:00
|
|
|
session->api().cloudPassword().clearUnconfirmedPassword();
|
2019-06-14 12:01:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-06-14 12:43:42 +00:00
|
|
|
auto fields = PasscodeBox::CloudFields::From(*current);
|
|
|
|
fields.turningOff = true;
|
2021-06-13 07:37:52 +00:00
|
|
|
auto box = Box<PasscodeBox>(session, fields);
|
2019-06-14 12:01:35 +00:00
|
|
|
|
|
|
|
rpl::merge(
|
2020-06-21 16:25:29 +00:00
|
|
|
box->newPasswordSet() | rpl::to_empty,
|
2019-06-14 12:01:35 +00:00
|
|
|
box->passwordReloadNeeded()
|
|
|
|
) | rpl::start_with_next([=] {
|
2021-08-02 19:06:33 +00:00
|
|
|
session->api().cloudPassword().reload();
|
2019-06-14 12:01:35 +00:00
|
|
|
}, box->lifetime());
|
|
|
|
|
|
|
|
box->clearUnconfirmedPassword(
|
|
|
|
) | rpl::start_with_next([=] {
|
2021-08-02 19:06:33 +00:00
|
|
|
session->api().cloudPassword().clearUnconfirmedPassword();
|
2019-06-14 12:01:35 +00:00
|
|
|
}, box->lifetime());
|
2021-06-13 07:37:52 +00:00
|
|
|
|
|
|
|
controller->show(std::move(box));
|
2019-06-14 12:01:35 +00:00
|
|
|
}
|
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
object_ptr<Ui::BoxContent> CloudPasswordAppOutdatedBox() {
|
2020-09-24 12:48:02 +00:00
|
|
|
const auto callback = [=](Fn<void()> &&close) {
|
2019-06-14 12:01:35 +00:00
|
|
|
Core::UpdateApplication();
|
2020-09-24 12:48:02 +00:00
|
|
|
close();
|
2019-06-14 12:01:35 +00:00
|
|
|
};
|
2021-10-18 22:28:08 +00:00
|
|
|
return Box<Ui::ConfirmBox>(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_passport_app_out_of_date(tr::now),
|
|
|
|
tr::lng_menu_update(tr::now),
|
2019-06-14 12:01:35 +00:00
|
|
|
callback);
|
|
|
|
}
|
|
|
|
|
2019-05-21 12:51:24 +00:00
|
|
|
void AddPrivacyButton(
|
2019-07-24 14:00:30 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2019-05-21 12:51:24 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> label,
|
2019-05-21 12:51:24 +00:00
|
|
|
Privacy::Key key,
|
2019-07-24 14:00:30 +00:00
|
|
|
Fn<std::unique_ptr<EditPrivacyController>()> controllerFactory) {
|
2019-05-21 12:51:24 +00:00
|
|
|
const auto shower = Ui::CreateChild<rpl::lifetime>(container.get());
|
2019-07-24 14:00:30 +00:00
|
|
|
const auto session = &controller->session();
|
2019-05-21 12:51:24 +00:00
|
|
|
AddButtonWithLabel(
|
|
|
|
container,
|
2019-06-18 12:16:43 +00:00
|
|
|
std::move(label),
|
2019-07-24 14:00:30 +00:00
|
|
|
PrivacyString(session, key),
|
2019-05-21 12:51:24 +00:00
|
|
|
st::settingsButton
|
|
|
|
)->addClickHandler([=] {
|
2021-07-31 14:11:53 +00:00
|
|
|
*shower = session->api().userPrivacy().value(
|
2019-05-21 12:51:24 +00:00
|
|
|
key
|
|
|
|
) | rpl::take(
|
|
|
|
1
|
2021-07-31 14:11:53 +00:00
|
|
|
) | rpl::start_with_next([=](const Privacy::Rule &value) {
|
2021-06-13 07:37:52 +00:00
|
|
|
controller->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-05-21 12:51:24 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-11-29 13:29:45 +00:00
|
|
|
rpl::producer<Type> PrivacySecurity::sectionShowOther() {
|
|
|
|
return _showOther.events();
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2020-09-12 14:10:56 +00:00
|
|
|
auto updateOnTick = rpl::single(
|
|
|
|
) | rpl::then(base::timer_each(kUpdateTimeout));
|
|
|
|
const auto trigger = [=] {
|
|
|
|
return rpl::duplicate(updateOnTick);
|
|
|
|
};
|
|
|
|
|
|
|
|
SetupPrivacy(controller, content, trigger());
|
2021-11-29 13:29:45 +00:00
|
|
|
SetupSessionsList(controller, content, trigger(), [=](Type type) {
|
|
|
|
_showOther.fire_copy(type);
|
|
|
|
});
|
2019-07-24 14:00:30 +00:00
|
|
|
SetupLocalPasscode(controller, content);
|
|
|
|
SetupCloudPassword(controller, content);
|
2019-12-09 12:59:08 +00:00
|
|
|
#if !defined OS_MAC_STORE && !defined OS_WIN_STORE
|
2020-09-12 14:10:56 +00:00
|
|
|
SetupSensitiveContent(controller, content, trigger());
|
2019-12-09 12:59:08 +00:00
|
|
|
#else // !OS_MAC_STORE && !OS_WIN_STORE
|
|
|
|
AddDivider(content);
|
|
|
|
#endif // !OS_MAC_STORE && !OS_WIN_STORE
|
2021-12-02 09:35:38 +00:00
|
|
|
SetupArchiveAndMute(controller, content);
|
2020-09-12 14:10:56 +00:00
|
|
|
SetupSelfDestruction(controller, content, trigger());
|
2021-04-07 11:43:32 +00:00
|
|
|
AddDivider(content);
|
|
|
|
SetupBotsAndWebsites(controller, content);
|
2018-09-05 19:05:49 +00:00
|
|
|
|
|
|
|
Ui::ResizeFitChild(this, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|