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 "settings/settings_common.h"
|
2018-09-11 19:00:23 +00:00
|
|
|
#include "settings/settings_privacy_controllers.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"
|
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "boxes/self_destruction_box.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"
|
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"
|
|
|
|
#include "info/profile/info_profile_button.h"
|
|
|
|
#include "platform/platform_specific.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"
|
|
|
|
#include "auth_session.h"
|
|
|
|
#include "apiwrap.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
|
|
|
|
|
|
|
namespace Settings {
|
2018-09-09 12:10:54 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
rpl::producer<> PasscodeChanges() {
|
|
|
|
return rpl::single(
|
|
|
|
rpl::empty_value()
|
|
|
|
) | rpl::then(base::ObservableViewer(
|
|
|
|
Global::RefLocalPasscodeChanged()
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2018-11-16 05:40:42 +00:00
|
|
|
QString PrivacyBase(
|
|
|
|
ApiWrap::Privacy::Key key,
|
|
|
|
ApiWrap::Privacy::Option option) {
|
|
|
|
const auto phrase = [&] {
|
|
|
|
using Key = ApiWrap::Privacy::Key;
|
2018-09-12 17:02:30 +00:00
|
|
|
using Option = ApiWrap::Privacy::Option;
|
2018-11-16 05:40:42 +00:00
|
|
|
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.");
|
2018-09-12 17:02:30 +00:00
|
|
|
}
|
|
|
|
}();
|
2018-11-16 05:40:42 +00:00
|
|
|
return lang(phrase);
|
2018-09-12 17:02:30 +00:00
|
|
|
}
|
|
|
|
|
2018-09-09 12:10:54 +00:00
|
|
|
void SetupPrivacy(not_null<Ui::VerticalLayout*> container) {
|
2018-09-15 10:37:48 +00:00
|
|
|
AddSkip(container, st::settingsPrivacySkip);
|
2018-09-09 12:10:54 +00:00
|
|
|
AddSubsectionTitle(container, lng_settings_privacy_title);
|
2018-09-15 10:37:48 +00:00
|
|
|
|
2018-09-09 12:10:54 +00:00
|
|
|
AddButton(
|
|
|
|
container,
|
|
|
|
lng_settings_blocked_users,
|
2018-09-17 10:52:34 +00:00
|
|
|
st::settingsButton
|
2018-09-09 12:10:54 +00:00
|
|
|
)->addClickHandler([] {
|
|
|
|
const auto initBox = [](not_null<PeerListBox*> box) {
|
|
|
|
box->addButton(langFactory(lng_close), [=] {
|
|
|
|
box->closeBox();
|
|
|
|
});
|
|
|
|
box->addLeftButton(langFactory(lng_blocked_list_add), [] {
|
2018-09-11 19:00:23 +00:00
|
|
|
BlockedBoxController::BlockNewUser();
|
2018-09-09 12:10:54 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
Ui::show(Box<PeerListBox>(
|
2018-09-11 19:00:23 +00:00
|
|
|
std::make_unique<BlockedBoxController>(),
|
2018-09-09 12:10:54 +00:00
|
|
|
initBox));
|
|
|
|
});
|
|
|
|
|
2018-09-11 09:11:52 +00:00
|
|
|
using Privacy = ApiWrap::Privacy;
|
|
|
|
const auto PrivacyString = [](Privacy::Key key) {
|
|
|
|
Auth().api().reloadPrivacy(key);
|
|
|
|
return Auth().api().privacyValue(
|
|
|
|
key
|
2018-11-16 05:40:42 +00:00
|
|
|
) | rpl::map([=](const Privacy &value) {
|
2018-09-11 09:11:52 +00:00
|
|
|
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()) {
|
2018-11-16 05:40:42 +00:00
|
|
|
return PrivacyBase(key, value.option)
|
|
|
|
+ " (" + add.join(", ") + ")";
|
2018-09-11 09:11:52 +00:00
|
|
|
} else {
|
2018-11-16 05:40:42 +00:00
|
|
|
return PrivacyBase(key, value.option);
|
2018-09-11 09:11:52 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
const auto add = [&](LangKey label, Privacy::Key key, auto controller) {
|
2018-11-21 10:09:46 +00:00
|
|
|
const auto shower = Ui::CreateChild<rpl::lifetime>(container.get());
|
2018-09-11 09:11:52 +00:00
|
|
|
AddButtonWithLabel(
|
|
|
|
container,
|
|
|
|
label,
|
|
|
|
PrivacyString(key),
|
2018-09-17 10:52:34 +00:00
|
|
|
st::settingsButton
|
2018-09-11 09:11:52 +00:00
|
|
|
)->addClickHandler([=] {
|
2018-09-19 09:06:21 +00:00
|
|
|
*shower = Auth().api().privacyValue(
|
|
|
|
key
|
|
|
|
) | rpl::take(
|
|
|
|
1
|
|
|
|
) | rpl::start_with_next([=](const Privacy &value) {
|
|
|
|
Ui::show(Box<EditPrivacyBox>(
|
|
|
|
controller(),
|
|
|
|
value));
|
|
|
|
});
|
2018-09-11 09:11:52 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
add(
|
2018-09-09 12:10:54 +00:00
|
|
|
lng_settings_last_seen,
|
2018-09-11 09:11:52 +00:00
|
|
|
Privacy::Key::LastSeen,
|
|
|
|
[] { return std::make_unique<LastSeenPrivacyController>(); });
|
|
|
|
add(
|
2018-09-09 12:10:54 +00:00
|
|
|
lng_settings_calls,
|
2018-09-11 09:11:52 +00:00
|
|
|
Privacy::Key::Calls,
|
|
|
|
[] { return std::make_unique<CallsPrivacyController>(); });
|
2018-10-24 09:07:54 +00:00
|
|
|
add(
|
|
|
|
lng_settings_calls_peer_to_peer,
|
|
|
|
Privacy::Key::CallsPeer2Peer,
|
|
|
|
[] { return std::make_unique<CallsPeer2PeerPrivacyController>(); });
|
2018-09-11 09:11:52 +00:00
|
|
|
add(
|
2018-09-09 12:10:54 +00:00
|
|
|
lng_settings_groups_invite,
|
2018-09-11 09:11:52 +00:00
|
|
|
Privacy::Key::Invites,
|
|
|
|
[] { return std::make_unique<GroupsInvitePrivacyController>(); });
|
2018-09-09 12:10:54 +00:00
|
|
|
|
2018-09-10 12:18:39 +00:00
|
|
|
AddSkip(container, st::settingsPrivacySecurityPadding);
|
2018-09-09 12:10:54 +00:00
|
|
|
AddDividerText(
|
|
|
|
container,
|
|
|
|
Lang::Viewer(lng_settings_group_privacy_about));
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2018-09-15 10:37:48 +00:00
|
|
|
void SetupLocalPasscode(not_null<Ui::VerticalLayout*> container) {
|
|
|
|
AddSkip(container);
|
|
|
|
AddSubsectionTitle(container, lng_settings_passcode_title);
|
|
|
|
|
2018-09-09 12:10:54 +00:00
|
|
|
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<Button>(
|
|
|
|
container,
|
|
|
|
std::move(text),
|
2018-09-17 10:52:34 +00:00
|
|
|
st::settingsButton)
|
2018-09-09 12:10:54 +00:00
|
|
|
)->addClickHandler([] {
|
|
|
|
Ui::show(Box<PasscodeBox>(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,
|
|
|
|
Lang::Viewer(lng_settings_passcode_disable),
|
2018-09-17 10:52:34 +00:00
|
|
|
st::settingsButton)
|
2018-09-09 12:10:54 +00:00
|
|
|
)->addClickHandler([] {
|
|
|
|
Ui::show(Box<PasscodeBox>(true));
|
|
|
|
});
|
|
|
|
|
|
|
|
const auto label = psIdleSupported()
|
|
|
|
? lng_passcode_autolock_away
|
|
|
|
: lng_passcode_autolock_inactive;
|
|
|
|
auto value = PasscodeChanges(
|
|
|
|
) | rpl::map([] {
|
|
|
|
const auto autolock = Global::AutoLock();
|
|
|
|
return (autolock % 3600)
|
|
|
|
? lng_passcode_autolock_minutes(lt_count, autolock / 60)
|
|
|
|
: lng_passcode_autolock_hours(lt_count, autolock / 3600);
|
|
|
|
});
|
|
|
|
|
2018-09-17 10:52:34 +00:00
|
|
|
AddButtonWithLabel(
|
|
|
|
inner,
|
|
|
|
label,
|
|
|
|
std::move(value),
|
|
|
|
st::settingsButton
|
|
|
|
)->addClickHandler([] {
|
2018-09-09 12:10:54 +00:00
|
|
|
Ui::show(Box<AutoLockBox>());
|
|
|
|
});
|
|
|
|
|
|
|
|
wrap->toggleOn(base::duplicate(has));
|
|
|
|
|
2018-09-15 10:37:48 +00:00
|
|
|
AddSkip(container);
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CheckEditCloudPassword() {
|
|
|
|
const auto current = Auth().api().passwordStateCurrent();
|
|
|
|
Assert(current.has_value());
|
|
|
|
if (!current->unknownAlgorithm
|
|
|
|
&& current->newPassword
|
|
|
|
&& current->newSecureSecret) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
auto box = std::make_shared<QPointer<BoxContent>>();
|
|
|
|
const auto callback = [=] {
|
|
|
|
Core::UpdateApplication();
|
|
|
|
if (*box) (*box)->closeBox();
|
|
|
|
};
|
|
|
|
*box = Ui::show(Box<ConfirmBox>(
|
|
|
|
lang(lng_passport_app_out_of_date),
|
|
|
|
lang(lng_menu_update),
|
|
|
|
callback));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void EditCloudPassword() {
|
|
|
|
const auto current = Auth().api().passwordStateCurrent();
|
|
|
|
Assert(current.has_value());
|
|
|
|
|
|
|
|
const auto box = Ui::show(Box<PasscodeBox>(
|
|
|
|
current->request,
|
|
|
|
current->newPassword,
|
|
|
|
current->hasRecovery,
|
|
|
|
current->notEmptyPassport,
|
|
|
|
current->hint,
|
|
|
|
current->newSecureSecret));
|
2018-11-07 09:39:31 +00:00
|
|
|
|
2018-09-09 12:10:54 +00:00
|
|
|
rpl::merge(
|
|
|
|
box->newPasswordSet() | rpl::map([] { return rpl::empty_value(); }),
|
|
|
|
box->passwordReloadNeeded()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
Auth().api().reloadPasswordState();
|
|
|
|
}, box->lifetime());
|
2018-11-07 09:39:31 +00:00
|
|
|
|
|
|
|
box->clearUnconfirmedPassword(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
Auth().api().clearUnconfirmedPassword();
|
|
|
|
}, box->lifetime());
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveCloudPassword() {
|
|
|
|
const auto current = Auth().api().passwordStateCurrent();
|
|
|
|
Assert(current.has_value());
|
|
|
|
|
|
|
|
if (!current->request) {
|
|
|
|
Auth().api().clearUnconfirmedPassword();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto box = Ui::show(Box<PasscodeBox>(
|
|
|
|
current->request,
|
|
|
|
current->newPassword,
|
|
|
|
current->hasRecovery,
|
|
|
|
current->notEmptyPassport,
|
|
|
|
current->hint,
|
|
|
|
current->newSecureSecret,
|
|
|
|
true));
|
2018-11-07 09:39:31 +00:00
|
|
|
|
2018-09-09 12:10:54 +00:00
|
|
|
rpl::merge(
|
|
|
|
box->newPasswordSet(
|
|
|
|
) | rpl::map([] { return rpl::empty_value(); }),
|
|
|
|
box->passwordReloadNeeded()
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
Auth().api().reloadPasswordState();
|
|
|
|
}, box->lifetime());
|
2018-11-07 09:39:31 +00:00
|
|
|
|
|
|
|
box->clearUnconfirmedPassword(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
Auth().api().clearUnconfirmedPassword();
|
|
|
|
}, box->lifetime());
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
2018-09-15 10:37:48 +00:00
|
|
|
void SetupCloudPassword(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);
|
|
|
|
AddSubsectionTitle(container, lng_settings_password_title);
|
|
|
|
|
2018-09-09 12:10:54 +00:00
|
|
|
auto has = rpl::single(
|
|
|
|
false
|
|
|
|
) | rpl::then(Auth().api().passwordState(
|
|
|
|
) | rpl::map([](const State &state) {
|
|
|
|
return state.request
|
|
|
|
|| state.unknownAlgorithm
|
|
|
|
|| !state.unconfirmedPattern.isEmpty();
|
|
|
|
})) | rpl::distinct_until_changed();
|
|
|
|
auto pattern = Auth().api().passwordState(
|
|
|
|
) | rpl::map([](const State &state) {
|
|
|
|
return state.unconfirmedPattern;
|
|
|
|
});
|
|
|
|
auto confirmation = rpl::single(
|
|
|
|
lang(lng_profile_loading)
|
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) {
|
2018-11-07 09:39:31 +00:00
|
|
|
return lng_cloud_password_waiting_code(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
|
|
|
|
));
|
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(
|
|
|
|
Lang::Viewer(lng_cloud_password_set),
|
|
|
|
Lang::Viewer(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(
|
2018-12-25 10:52:53 +00:00
|
|
|
noconfirmed
|
|
|
|
) | rpl::map(
|
|
|
|
!_1
|
|
|
|
))->setDuration(0);
|
2018-09-09 12:10:54 +00:00
|
|
|
change->entity()->addClickHandler([] {
|
|
|
|
if (CheckEditCloudPassword()) {
|
|
|
|
EditCloudPassword();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
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,
|
2018-11-07 09:39:31 +00:00
|
|
|
Lang::Viewer(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);
|
2018-11-07 09:39:31 +00:00
|
|
|
confirm->entity()->addClickHandler([] {
|
|
|
|
const auto state = Auth().api().passwordStateCurrent();
|
2018-12-25 10:52:53 +00:00
|
|
|
if (!state) {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-07 09:39:31 +00:00
|
|
|
auto validation = ConfirmRecoveryEmail(state->unconfirmedPattern);
|
|
|
|
|
|
|
|
std::move(
|
|
|
|
validation.reloadRequests
|
|
|
|
) | rpl::start_with_next([] {
|
|
|
|
Auth().api().reloadPasswordState();
|
|
|
|
}, validation.box->lifetime());
|
|
|
|
|
|
|
|
std::move(
|
|
|
|
validation.cancelRequests
|
|
|
|
) | rpl::start_with_next([] {
|
|
|
|
Auth().api().clearUnconfirmedPassword();
|
|
|
|
}, validation.box->lifetime());
|
|
|
|
|
|
|
|
Ui::show(std::move(validation.box));
|
|
|
|
});
|
|
|
|
|
|
|
|
const auto remove = [] {
|
2018-09-09 12:10:54 +00:00
|
|
|
if (CheckEditCloudPassword()) {
|
|
|
|
RemoveCloudPassword();
|
|
|
|
}
|
2018-11-07 09:39:31 +00:00
|
|
|
};
|
|
|
|
const auto disable = container->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Button>>(
|
|
|
|
container,
|
|
|
|
object_ptr<Button>(
|
|
|
|
container,
|
|
|
|
Lang::Viewer(lng_settings_password_disable),
|
|
|
|
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);
|
|
|
|
|
|
|
|
const auto abort = container->add(
|
|
|
|
object_ptr<Ui::SlideWrap<Button>>(
|
|
|
|
container,
|
|
|
|
object_ptr<Button>(
|
|
|
|
container,
|
|
|
|
Lang::Viewer(lng_settings_password_abort),
|
|
|
|
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) {
|
|
|
|
Auth().api().reloadPasswordState();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
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);
|
|
|
|
|
|
|
|
Auth().api().reloadPasswordState();
|
2018-09-15 10:37:48 +00:00
|
|
|
|
|
|
|
AddSkip(container);
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SetupSelfDestruction(not_null<Ui::VerticalLayout*> container) {
|
2018-10-09 10:40:26 +00:00
|
|
|
AddDivider(container);
|
2018-09-15 10:37:48 +00:00
|
|
|
AddSkip(container);
|
|
|
|
AddSubsectionTitle(container, lng_settings_destroy_title);
|
|
|
|
|
2018-09-17 17:31:01 +00:00
|
|
|
Auth().api().reloadSelfDestruct();
|
|
|
|
const auto label = [] {
|
|
|
|
return Auth().api().selfDestructValue(
|
|
|
|
) | rpl::map(
|
|
|
|
SelfDestructionBox::DaysLabel
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
AddButtonWithLabel(
|
2018-09-09 12:10:54 +00:00
|
|
|
container,
|
2018-09-17 17:31:01 +00:00
|
|
|
lng_settings_destroy_if,
|
|
|
|
label(),
|
2018-09-17 10:52:34 +00:00
|
|
|
st::settingsButton
|
2018-09-09 12:10:54 +00:00
|
|
|
)->addClickHandler([] {
|
2018-09-17 17:31:01 +00:00
|
|
|
Ui::show(Box<SelfDestructionBox>(Auth().api().selfDestructValue()));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void SetupSessionsList(not_null<Ui::VerticalLayout*> container) {
|
2018-09-15 10:37:48 +00:00
|
|
|
AddSkip(container);
|
|
|
|
AddSubsectionTitle(container, lng_settings_sessions_title);
|
|
|
|
|
2018-09-09 12:10:54 +00:00
|
|
|
AddButton(
|
|
|
|
container,
|
|
|
|
lng_settings_show_sessions,
|
2018-09-17 10:52:34 +00:00
|
|
|
st::settingsButton
|
2018-09-09 12:10:54 +00:00
|
|
|
)->addClickHandler([] {
|
|
|
|
Ui::show(Box<SessionsBox>());
|
|
|
|
});
|
2018-09-10 12:18:39 +00:00
|
|
|
AddSkip(container, st::settingsPrivacySecurityPadding);
|
2018-09-09 12:10:54 +00:00
|
|
|
AddDividerText(
|
|
|
|
container,
|
|
|
|
Lang::Viewer(lng_settings_sessions_about));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
2018-09-05 19:05:49 +00:00
|
|
|
|
|
|
|
PrivacySecurity::PrivacySecurity(QWidget *parent, not_null<UserData*> self)
|
|
|
|
: Section(parent)
|
|
|
|
, _self(self) {
|
|
|
|
setupContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrivacySecurity::setupContent() {
|
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
|
2018-09-09 12:10:54 +00:00
|
|
|
SetupPrivacy(content);
|
2018-10-09 10:40:26 +00:00
|
|
|
SetupSessionsList(content);
|
2018-09-15 10:37:48 +00:00
|
|
|
SetupLocalPasscode(content);
|
|
|
|
SetupCloudPassword(content);
|
|
|
|
SetupSelfDestruction(content);
|
2018-09-05 19:05:49 +00:00
|
|
|
|
|
|
|
Ui::ResizeFitChild(this, content);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|