mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-25 04:38:23 +00:00
Implement privacy and security settings section.
This commit is contained in:
parent
b8c2c3991f
commit
633ff4b60e
@ -335,6 +335,15 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
"lng_settings_connection_type" = "Connection type";
|
||||
"lng_settings_downloading_update" = "Downloading update {progress}...";
|
||||
"lng_settings_use_night_mode" = "Use night mode";
|
||||
"lng_settings_privacy_title" = "Privacy";
|
||||
"lng_settings_last_seen" = "Last seen";
|
||||
"lng_settings_calls" = "Calls";
|
||||
"lng_settings_groups_invite" = "Groups";
|
||||
"lng_settings_group_privacy_about" = "Change who can add you to groups and channel.";
|
||||
"lng_settings_security_title" = "Security";
|
||||
"lng_settings_sessions_about" = "Control your sessions on other devices.";
|
||||
"lng_settings_passcode_disable" = "Disable passcode";
|
||||
"lng_settings_password_disable" = "Disable cloud password";
|
||||
|
||||
"lng_backgrounds_header" = "Choose your new chat background";
|
||||
"lng_theme_sure_keep" = "Keep this theme?";
|
||||
|
@ -18,6 +18,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "data/data_session.h"
|
||||
#include "dialogs/dialogs_key.h"
|
||||
#include "core/tl_help.h"
|
||||
#include "core/core_cloud_password.h"
|
||||
#include "base/openssl_help.h"
|
||||
#include "base/overload.h"
|
||||
#include "observer_peer.h"
|
||||
#include "lang/lang_keys.h"
|
||||
@ -4889,6 +4891,61 @@ void ApiWrap::clearPeerPhoto(not_null<PhotoData*> photo) {
|
||||
}
|
||||
}
|
||||
|
||||
void ApiWrap::reloadPasswordState() {
|
||||
if (_passwordRequestId) {
|
||||
return;
|
||||
}
|
||||
_passwordRequestId = request(MTPaccount_GetPassword(
|
||||
)).done([=](const MTPaccount_Password &result) {
|
||||
_passwordRequestId = 0;
|
||||
result.match([&](const MTPDaccount_password &data) {
|
||||
openssl::AddRandomSeed(bytes::make_span(data.vsecure_random.v));
|
||||
if (_passwordState) {
|
||||
*_passwordState = Core::ParseCloudPasswordState(data);
|
||||
} else {
|
||||
_passwordState = std::make_unique<Core::CloudPasswordState>(
|
||||
Core::ParseCloudPasswordState(data));
|
||||
}
|
||||
_passwordStateChanges.fire_copy(*_passwordState);
|
||||
});
|
||||
}).fail([=](const RPCError &error) {
|
||||
_passwordRequestId = 0;
|
||||
}).send();
|
||||
}
|
||||
|
||||
void ApiWrap::clearUnconfirmedPassword() {
|
||||
_passwordRequestId = request(MTPaccount_UpdatePasswordSettings(
|
||||
MTP_inputCheckPasswordEmpty(),
|
||||
MTP_account_passwordInputSettings(
|
||||
MTP_flags(
|
||||
MTPDaccount_passwordInputSettings::Flag::f_email),
|
||||
MTP_passwordKdfAlgoUnknown(), // new_algo
|
||||
MTP_bytes(QByteArray()), // new_password_hash
|
||||
MTP_string(QString()), // hint
|
||||
MTP_string(QString()), // email
|
||||
MTPSecureSecretSettings())
|
||||
)).done([=](const MTPBool &result) {
|
||||
_passwordRequestId = 0;
|
||||
reloadPasswordState();
|
||||
}).fail([=](const RPCError &error) {
|
||||
_passwordRequestId = 0;
|
||||
reloadPasswordState();
|
||||
}).send();
|
||||
}
|
||||
|
||||
rpl::producer<Core::CloudPasswordState> ApiWrap::passwordState() const {
|
||||
return _passwordState
|
||||
? _passwordStateChanges.events_starting_with_copy(*_passwordState)
|
||||
: _passwordStateChanges.events();
|
||||
}
|
||||
|
||||
auto ApiWrap::passwordStateCurrent() const
|
||||
->base::optional<Core::CloudPasswordState> {
|
||||
return _passwordState
|
||||
? base::make_optional(*_passwordState)
|
||||
: base::none;
|
||||
}
|
||||
|
||||
void ApiWrap::readServerHistory(not_null<History*> history) {
|
||||
if (history->unreadCount()) {
|
||||
readServerHistoryForce(history);
|
||||
|
@ -37,6 +37,10 @@ namespace Dialogs {
|
||||
class Key;
|
||||
} // namespace Dialogs
|
||||
|
||||
namespace Core {
|
||||
struct CloudPasswordState;
|
||||
} // namespace Core
|
||||
|
||||
namespace Api {
|
||||
|
||||
inline const MTPVector<MTPChat> *getChatsFromMessagesChats(const MTPmessages_Chats &chats) {
|
||||
@ -327,6 +331,11 @@ public:
|
||||
void uploadPeerPhoto(not_null<PeerData*> peer, QImage &&image);
|
||||
void clearPeerPhoto(not_null<PhotoData*> photo);
|
||||
|
||||
void reloadPasswordState();
|
||||
void clearUnconfirmedPassword();
|
||||
rpl::producer<Core::CloudPasswordState> passwordState() const;
|
||||
base::optional<Core::CloudPasswordState> passwordStateCurrent() const;
|
||||
|
||||
~ApiWrap();
|
||||
|
||||
private:
|
||||
@ -659,4 +668,8 @@ private:
|
||||
|
||||
base::flat_map<FullMsgId, not_null<PeerData*>> _peerPhotoUploads;
|
||||
|
||||
mtpRequestId _passwordRequestId = 0;
|
||||
std::unique_ptr<Core::CloudPasswordState> _passwordState;
|
||||
rpl::event_stream<Core::CloudPasswordState> _passwordStateChanges;
|
||||
|
||||
};
|
||||
|
@ -303,4 +303,22 @@ bytes::vector ComputeSecureSecretHash(
|
||||
});
|
||||
}
|
||||
|
||||
CloudPasswordState ParseCloudPasswordState(
|
||||
const MTPDaccount_password &data) {
|
||||
auto result = CloudPasswordState();
|
||||
result.request = ParseCloudPasswordCheckRequest(data);
|
||||
result.unknownAlgorithm = data.has_current_algo() && !result.request;
|
||||
result.hasRecovery = data.is_has_recovery();
|
||||
result.notEmptyPassport = data.is_has_secure_values();
|
||||
result.hint = data.has_hint() ? qs(data.vhint) : QString();
|
||||
result.newPassword = ValidateNewCloudPasswordAlgo(
|
||||
ParseCloudPasswordAlgo(data.vnew_algo));
|
||||
result.newSecureSecret = ValidateNewSecureSecretAlgo(
|
||||
ParseSecureSecretAlgo(data.vnew_secure_algo));
|
||||
result.unconfirmedPattern = data.has_email_unconfirmed_pattern()
|
||||
? qs(data.vemail_unconfirmed_pattern)
|
||||
: QString();
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace Core
|
@ -120,4 +120,18 @@ bytes::vector ComputeSecureSecretHash(
|
||||
const SecureSecretAlgo &algo,
|
||||
bytes::const_span password);
|
||||
|
||||
struct CloudPasswordState {
|
||||
CloudPasswordCheckRequest request;
|
||||
bool unknownAlgorithm = false;
|
||||
bool hasRecovery = false;
|
||||
bool notEmptyPassport = false;
|
||||
QString hint;
|
||||
CloudPasswordAlgo newPassword;
|
||||
SecureSecretAlgo newSecureSecret;
|
||||
QString unconfirmedPattern;
|
||||
};
|
||||
|
||||
CloudPasswordState ParseCloudPasswordState(
|
||||
const MTPDaccount_password &data);
|
||||
|
||||
} // namespace Core
|
||||
|
@ -13,13 +13,14 @@ using "boxes/boxes.style";
|
||||
settingsSectionButton: InfoProfileButton(infoProfileButton) {
|
||||
font: boxTextFont;
|
||||
}
|
||||
settingsButton: InfoProfileButton(settingsSectionButton) {
|
||||
padding: margins(28px, 10px, 8px, 8px);
|
||||
settingsGeneralButton: InfoProfileButton(settingsSectionButton) {
|
||||
padding: margins(28px, 10px, 22px, 8px);
|
||||
}
|
||||
settingsChatButton: InfoProfileButton(settingsSectionButton) {
|
||||
padding: margins(22px, 10px, 8px, 8px);
|
||||
settingsButton: InfoProfileButton(settingsSectionButton) {
|
||||
padding: margins(22px, 10px, 22px, 8px);
|
||||
}
|
||||
settingsSectionSkip: infoProfileSkip;
|
||||
settingsSeparatorPadding: margins(22px, infoProfileSkip, 0px, infoProfileSkip);
|
||||
settingsButtonRightPosition: point(28px, 10px);
|
||||
settingsButtonRight: FlatLabel(defaultFlatLabel) {
|
||||
textFg: windowActiveTextFg;
|
||||
@ -39,6 +40,7 @@ settingsUpdateState: FlatLabel(defaultFlatLabel) {
|
||||
settingsUpdate: InfoProfileButton(infoMainButton, settingsButton) {
|
||||
}
|
||||
settingsUpdateStatePosition: point(28px, 30px);
|
||||
settingsDividerLabelPadding: margins(22px, 7px, 22px, 14px);
|
||||
|
||||
settingsSendType: defaultBoxCheckbox;
|
||||
settingsSendTypePadding: margins(22px, 5px, 10px, 5px);
|
||||
@ -55,7 +57,7 @@ settingsDownloadPathPadding: margins(22px, 1px, 10px, 0px);
|
||||
|
||||
settingsBackgroundThumb: 76px;
|
||||
settingsThumbSkip: 16px;
|
||||
settingsBackgroundTitle: FlatLabel(defaultFlatLabel) {
|
||||
settingsSubsectionTitle: FlatLabel(defaultFlatLabel) {
|
||||
style: TextStyle(semiboldTextStyle) {
|
||||
font: font(boxFontSize semibold);
|
||||
linkFont: font(boxFontSize semibold);
|
||||
@ -63,7 +65,14 @@ settingsBackgroundTitle: FlatLabel(defaultFlatLabel) {
|
||||
}
|
||||
textFg: windowActiveTextFg;
|
||||
}
|
||||
settingsBackgroundTitlePadding: margins(22px, 7px, 10px, 9px);
|
||||
settingsSubsectionTitlePadding: margins(22px, 7px, 10px, 9px);
|
||||
settingsBackgroundPadding: margins(22px, 8px, 10px, 8px);
|
||||
settingsFromGalleryTop: 2px;
|
||||
settingsFromFileTop: 14px;
|
||||
|
||||
settingsCloudPasswordLabel: FlatLabel(defaultFlatLabel) {
|
||||
textFg: windowSubTextFg;
|
||||
style: boxTextStyle;
|
||||
maxHeight: 20px;
|
||||
}
|
||||
settingsCloudPasswordLabelPadding: margins(22px, 8px, 10px, 8px);
|
||||
|
@ -535,7 +535,7 @@ void SetupMediaOptions(not_null<Ui::VerticalLayout*> container) {
|
||||
AddButton(
|
||||
container,
|
||||
lng_media_auto_settings,
|
||||
st::settingsChatButton
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
Ui::show(Box<AutoDownloadBox>());
|
||||
});
|
||||
@ -543,7 +543,7 @@ void SetupMediaOptions(not_null<Ui::VerticalLayout*> container) {
|
||||
AddButton(
|
||||
container,
|
||||
lng_stickers_you_have,
|
||||
st::settingsChatButton
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
Ui::show(Box<StickersBox>(StickersBox::Section::Installed));
|
||||
});
|
||||
@ -555,12 +555,7 @@ void SetupChatBackground(not_null<Ui::VerticalLayout*> container) {
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
|
||||
container->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
Lang::Viewer(lng_settings_section_background),
|
||||
st::settingsBackgroundTitle),
|
||||
st::settingsBackgroundTitlePadding);
|
||||
AddSubsectionTitle(container, lng_settings_section_background);
|
||||
|
||||
container->add(
|
||||
object_ptr<BackgroundRow>(container),
|
||||
@ -637,7 +632,7 @@ void SetupThemeOptions(not_null<Ui::VerticalLayout*> container) {
|
||||
AddButton(
|
||||
container,
|
||||
lng_settings_use_night_mode,
|
||||
st::settingsChatButton
|
||||
st::settingsButton
|
||||
)->toggleOn(
|
||||
rpl::single(Window::Theme::IsNightMode())
|
||||
)->toggledValue(
|
||||
@ -657,9 +652,9 @@ void SetupThemeOptions(not_null<Ui::VerticalLayout*> container) {
|
||||
AddButton(
|
||||
container,
|
||||
lng_settings_bg_edit_theme,
|
||||
st::settingsChatButton
|
||||
st::settingsButton
|
||||
)->addClickHandler(App::LambdaDelayed(
|
||||
st::settingsChatButton.ripple.hideDuration,
|
||||
st::settingsButton.ripple.hideDuration,
|
||||
container,
|
||||
[] { Window::Theme::Editor::Start(); }));
|
||||
|
||||
@ -670,7 +665,7 @@ void SetupThemeOptions(not_null<Ui::VerticalLayout*> container) {
|
||||
object_ptr<Button>(
|
||||
container,
|
||||
Lang::Viewer(lng_settings_bg_use_default),
|
||||
st::settingsChatButton))
|
||||
st::settingsButton))
|
||||
)->toggleOn(rpl::single(
|
||||
Window::Theme::SuggestThemeReset()
|
||||
) | rpl::then(base::ObservableViewer(
|
||||
|
@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "boxes/abstract_box.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "mainwindow.h"
|
||||
#include "styles/style_boxes.h"
|
||||
#include "styles/style_settings.h"
|
||||
|
||||
namespace Settings {
|
||||
@ -60,6 +61,18 @@ void AddDivider(not_null<Ui::VerticalLayout*> container) {
|
||||
container->add(object_ptr<BoxContentDivider>(container));
|
||||
}
|
||||
|
||||
void AddDividerText(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<QString> text) {
|
||||
container->add(object_ptr<Ui::DividerLabel>(
|
||||
container,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
std::move(text),
|
||||
st::boxDividerLabel),
|
||||
st::settingsDividerLabelPadding));
|
||||
}
|
||||
|
||||
not_null<Button*> AddButton(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
LangKey text,
|
||||
@ -70,12 +83,9 @@ not_null<Button*> AddButton(
|
||||
st));
|
||||
}
|
||||
|
||||
not_null<Button*> AddButtonWithLabel(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
LangKey text,
|
||||
rpl::producer<QString> label,
|
||||
const style::InfoProfileButton &st) {
|
||||
const auto button = AddButton(container, text, st);
|
||||
void CreateRightLabel(
|
||||
not_null<Button*> button,
|
||||
rpl::producer<QString> label) {
|
||||
const auto name = Ui::CreateChild<Ui::FlatLabel>(
|
||||
button.get(),
|
||||
std::move(label),
|
||||
@ -89,9 +99,29 @@ not_null<Button*> AddButtonWithLabel(
|
||||
st::settingsButtonRightPosition.y());
|
||||
}, name->lifetime());
|
||||
name->setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||
}
|
||||
|
||||
not_null<Button*> AddButtonWithLabel(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
LangKey text,
|
||||
rpl::producer<QString> label,
|
||||
const style::InfoProfileButton &st) {
|
||||
const auto button = AddButton(container, text, st);
|
||||
CreateRightLabel(button, std::move(label));
|
||||
return button;
|
||||
}
|
||||
|
||||
void AddSubsectionTitle(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
LangKey text) {
|
||||
container->add(
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
Lang::Viewer(text),
|
||||
st::settingsSubsectionTitle),
|
||||
st::settingsSubsectionTitlePadding);
|
||||
}
|
||||
|
||||
void FillMenu(Fn<void(Type)> showOther, MenuCallback addAction) {
|
||||
addAction(
|
||||
lang(lng_settings_edit_info),
|
||||
|
@ -61,6 +61,9 @@ object_ptr<Section> CreateSection(
|
||||
void AddSkip(not_null<Ui::VerticalLayout*> container);
|
||||
void AddSkip(not_null<Ui::VerticalLayout*> container, int skip);
|
||||
void AddDivider(not_null<Ui::VerticalLayout*> container);
|
||||
void AddDividerText(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<QString> text);
|
||||
not_null<Button*> AddButton(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
LangKey text,
|
||||
@ -70,6 +73,12 @@ not_null<Button*> AddButtonWithLabel(
|
||||
LangKey text,
|
||||
rpl::producer<QString> label,
|
||||
const style::InfoProfileButton &st);
|
||||
void CreateRightLabel(
|
||||
not_null<Button*> button,
|
||||
rpl::producer<QString> label);
|
||||
void AddSubsectionTitle(
|
||||
not_null<Ui::VerticalLayout*> conatiner,
|
||||
LangKey text);
|
||||
|
||||
using MenuCallback = Fn<QAction*(
|
||||
const QString &text,
|
||||
|
@ -51,7 +51,7 @@ void SetupConnectionType(not_null<Ui::VerticalLayout*> container) {
|
||||
) | rpl::then(base::ObservableViewer(
|
||||
Global::RefConnectionTypeChanged()
|
||||
)) | rpl::map(connectionType),
|
||||
st::settingsButton);
|
||||
st::settingsGeneralButton);
|
||||
button->addClickHandler([] {
|
||||
Ui::show(ProxiesBoxController::CreateOwningBox());
|
||||
});
|
||||
@ -65,7 +65,7 @@ void SetupStorageAndConnection(not_null<Ui::VerticalLayout*> container) {
|
||||
AddButton(
|
||||
container,
|
||||
lng_settings_local_storage,
|
||||
st::settingsButton
|
||||
st::settingsGeneralButton
|
||||
)->addClickHandler([] {
|
||||
LocalStorageBox::Show(&Auth().data().cache());
|
||||
});
|
||||
@ -105,7 +105,7 @@ void SetupUpdate(not_null<Ui::VerticalLayout*> container) {
|
||||
object_ptr<Button>(
|
||||
container,
|
||||
Lang::Viewer(lng_settings_check_now),
|
||||
st::settingsButton)));
|
||||
st::settingsGeneralButton)));
|
||||
const auto update = Ui::CreateChild<Button>(
|
||||
check->entity(),
|
||||
Lang::Viewer(lng_update_telegram) | Info::Profile::ToUpperValue(),
|
||||
@ -237,7 +237,7 @@ void SetupTray(not_null<Ui::VerticalLayout*> container) {
|
||||
const auto tray = AddButton(
|
||||
container,
|
||||
lng_settings_workmode_tray,
|
||||
st::settingsButton
|
||||
st::settingsGeneralButton
|
||||
)->toggleOn(trayEnabler->events_starting_with(trayEnabled()));
|
||||
|
||||
const auto taskbarEnabled = [] {
|
||||
@ -252,7 +252,7 @@ void SetupTray(not_null<Ui::VerticalLayout*> container) {
|
||||
? AddButton(
|
||||
container,
|
||||
lng_settings_workmode_window,
|
||||
st::settingsButton
|
||||
st::settingsGeneralButton
|
||||
)->toggleOn(taskbarEnabler->events_starting_with(taskbarEnabled()))
|
||||
: nullptr;
|
||||
|
||||
@ -299,7 +299,7 @@ void SetupTray(not_null<Ui::VerticalLayout*> container) {
|
||||
const auto autostart = AddButton(
|
||||
container,
|
||||
lng_settings_auto_start,
|
||||
st::settingsButton
|
||||
st::settingsGeneralButton
|
||||
)->toggleOn(rpl::single(cAutoStart()));
|
||||
const auto minimized = container->add(
|
||||
object_ptr<Ui::SlideWrap<Button>>(
|
||||
@ -307,11 +307,11 @@ void SetupTray(not_null<Ui::VerticalLayout*> container) {
|
||||
object_ptr<Button>(
|
||||
container,
|
||||
Lang::Viewer(lng_settings_start_min),
|
||||
st::settingsButton)));
|
||||
st::settingsGeneralButton)));
|
||||
const auto sendto = AddButton(
|
||||
container,
|
||||
lng_settings_add_sendto,
|
||||
st::settingsButton
|
||||
st::settingsGeneralButton
|
||||
)->toggleOn(rpl::single(cSendToMenu()));
|
||||
|
||||
const auto minimizedToggler = Ui::AttachAsChild(
|
||||
|
@ -292,6 +292,9 @@ void Main::setupContent(not_null<Window::Controller*> controller) {
|
||||
SetupHelp(content);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
|
||||
// If we load this in advance it won't jump when we open its' section.
|
||||
Auth().api().reloadPasswordState();
|
||||
}
|
||||
|
||||
rpl::producer<Type> Main::sectionShowOther() {
|
||||
|
@ -8,12 +8,401 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "settings/settings_privacy_security.h"
|
||||
|
||||
#include "settings/settings_common.h"
|
||||
#include "boxes/abstract_box.h"
|
||||
#include "old_settings/settings_privacy_controllers.h"
|
||||
#include "boxes/peer_list_box.h"
|
||||
#include "boxes/edit_privacy_box.h"
|
||||
#include "boxes/passcode_box.h"
|
||||
#include "boxes/autolock_box.h"
|
||||
#include "boxes/sessions_box.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "boxes/self_destruction_box.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/widgets/shadow.h"
|
||||
#include "ui/widgets/labels.h"
|
||||
#include "core/core_cloud_password.h"
|
||||
#include "core/update_checker.h"
|
||||
#include "info/profile/info_profile_button.h"
|
||||
#include "platform/platform_specific.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "data/data_session.h"
|
||||
#include "auth_session.h"
|
||||
#include "apiwrap.h"
|
||||
#include "styles/style_settings.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
||||
namespace Settings {
|
||||
namespace {
|
||||
|
||||
rpl::producer<> PasscodeChanges() {
|
||||
return rpl::single(
|
||||
rpl::empty_value()
|
||||
) | rpl::then(base::ObservableViewer(
|
||||
Global::RefLocalPasscodeChanged()
|
||||
));
|
||||
}
|
||||
|
||||
void SetupPrivacy(not_null<Ui::VerticalLayout*> container) {
|
||||
AddDivider(container);
|
||||
AddSkip(container);
|
||||
|
||||
AddSubsectionTitle(container, lng_settings_privacy_title);
|
||||
AddButton(
|
||||
container,
|
||||
lng_settings_blocked_users,
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
const auto initBox = [](not_null<PeerListBox*> box) {
|
||||
box->addButton(langFactory(lng_close), [=] {
|
||||
box->closeBox();
|
||||
});
|
||||
box->addLeftButton(langFactory(lng_blocked_list_add), [] {
|
||||
OldSettings::BlockedBoxController::BlockNewUser();
|
||||
});
|
||||
};
|
||||
Ui::show(Box<PeerListBox>(
|
||||
std::make_unique<OldSettings::BlockedBoxController>(),
|
||||
initBox));
|
||||
});
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
lng_settings_last_seen,
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
Ui::show(Box<EditPrivacyBox>(
|
||||
std::make_unique<OldSettings::LastSeenPrivacyController>()));
|
||||
});
|
||||
AddButton(
|
||||
container,
|
||||
lng_settings_calls,
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
Ui::show(Box<EditPrivacyBox>(
|
||||
std::make_unique<OldSettings::CallsPrivacyController>()));
|
||||
});
|
||||
AddButton(
|
||||
container,
|
||||
lng_settings_groups_invite,
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
Ui::show(Box<EditPrivacyBox>(
|
||||
std::make_unique<OldSettings::GroupsInvitePrivacyController>()));
|
||||
});
|
||||
|
||||
AddSkip(container);
|
||||
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));
|
||||
}
|
||||
|
||||
rpl::producer<bool> SetupLocalPasscode(
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
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),
|
||||
st::settingsButton)
|
||||
)->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),
|
||||
st::settingsButton)
|
||||
)->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);
|
||||
});
|
||||
|
||||
const auto autolock = inner->add(
|
||||
object_ptr<Button>(
|
||||
inner,
|
||||
Lang::Viewer(label),
|
||||
st::settingsButton));
|
||||
CreateRightLabel(autolock, std::move(value));
|
||||
autolock->addClickHandler([] {
|
||||
Ui::show(Box<AutoLockBox>());
|
||||
});
|
||||
|
||||
wrap->toggleOn(base::duplicate(has));
|
||||
|
||||
return std::move(has);
|
||||
}
|
||||
|
||||
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));
|
||||
rpl::merge(
|
||||
box->newPasswordSet() | rpl::map([] { return rpl::empty_value(); }),
|
||||
box->passwordReloadNeeded()
|
||||
) | rpl::start_with_next([=] {
|
||||
Auth().api().reloadPasswordState();
|
||||
}, box->lifetime());
|
||||
}
|
||||
|
||||
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));
|
||||
rpl::merge(
|
||||
box->newPasswordSet(
|
||||
) | rpl::map([] { return rpl::empty_value(); }),
|
||||
box->passwordReloadNeeded()
|
||||
) | rpl::start_with_next([=] {
|
||||
Auth().api().reloadPasswordState();
|
||||
}, box->lifetime());
|
||||
}
|
||||
|
||||
rpl::producer<bool> SetupCloudPassword(
|
||||
not_null<Ui::VerticalLayout*> container) {
|
||||
using State = Core::CloudPasswordState;
|
||||
|
||||
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)
|
||||
) | rpl::then(base::duplicate(
|
||||
pattern
|
||||
) | rpl::filter([](const QString &pattern) {
|
||||
return !pattern.isEmpty();
|
||||
}) | rpl::map([](const QString &pattern) {
|
||||
return lng_cloud_password_waiting(lt_email, pattern);
|
||||
}));
|
||||
auto unconfirmed = rpl::single(
|
||||
true
|
||||
) | rpl::then(base::duplicate(
|
||||
pattern
|
||||
) | rpl::map([](const QString &pattern) {
|
||||
return !pattern.isEmpty();
|
||||
}));
|
||||
const auto label = container->add(
|
||||
object_ptr<Ui::SlideWrap<Ui::FlatLabel>>(
|
||||
container,
|
||||
object_ptr<Ui::FlatLabel>(
|
||||
container,
|
||||
base::duplicate(confirmation),
|
||||
st::settingsCloudPasswordLabel),
|
||||
QMargins(
|
||||
st::settingsButton.padding.left(),
|
||||
st::settingsButton.padding.top(),
|
||||
st::settingsButton.padding.right(),
|
||||
(st::settingsButton.height
|
||||
- st::settingsCloudPasswordLabel.style.font->height
|
||||
+ st::settingsButton.padding.bottom()))));
|
||||
label->toggleOn(base::duplicate(unconfirmed))->setDuration(0);
|
||||
|
||||
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),
|
||||
st::settingsButton)));
|
||||
change->toggleOn(std::move(
|
||||
unconfirmed
|
||||
) | rpl::map([](bool unconfirmed) {
|
||||
return !unconfirmed;
|
||||
}))->setDuration(0);
|
||||
change->entity()->addClickHandler([] {
|
||||
if (CheckEditCloudPassword()) {
|
||||
EditCloudPassword();
|
||||
}
|
||||
});
|
||||
|
||||
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(base::duplicate(has));
|
||||
disable->entity()->addClickHandler([] {
|
||||
if (CheckEditCloudPassword()) {
|
||||
RemoveCloudPassword();
|
||||
}
|
||||
});
|
||||
|
||||
const auto reloadOnActivation = [=](Qt::ApplicationState state) {
|
||||
if (label->toggled() && state == Qt::ApplicationActive) {
|
||||
Auth().api().reloadPasswordState();
|
||||
}
|
||||
};
|
||||
QObject::connect(
|
||||
qApp,
|
||||
&QApplication::applicationStateChanged,
|
||||
label,
|
||||
reloadOnActivation);
|
||||
|
||||
Auth().api().reloadPasswordState();
|
||||
return std::move(has);
|
||||
}
|
||||
|
||||
void SetupSelfDestruction(not_null<Ui::VerticalLayout*> container) {
|
||||
AddButton(
|
||||
container,
|
||||
lng_settings_self_destruct,
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
Ui::show(Box<SelfDestructionBox>());
|
||||
});
|
||||
}
|
||||
|
||||
void SetupSessionsList(not_null<Ui::VerticalLayout*> container) {
|
||||
AddButton(
|
||||
container,
|
||||
lng_settings_show_sessions,
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
Ui::show(Box<SessionsBox>());
|
||||
});
|
||||
}
|
||||
|
||||
void SetupSecurity(not_null<Ui::VerticalLayout*> container) {
|
||||
AddSkip(container);
|
||||
|
||||
AddSubsectionTitle(container, lng_settings_security_title);
|
||||
|
||||
auto passcodeWide = SetupLocalPasscode(container);
|
||||
auto separator1 = AddSeparator(container);
|
||||
auto passwordWide = SetupCloudPassword(container);
|
||||
auto separator2 = AddSeparator(container);
|
||||
separator1->toggleOn(rpl::combine(
|
||||
std::move(passcodeWide),
|
||||
base::duplicate(passwordWide)
|
||||
) | rpl::map([](bool one, bool second) {
|
||||
return one || second;
|
||||
}));
|
||||
separator2->toggleOn(std::move(passwordWide));
|
||||
SetupSelfDestruction(container);
|
||||
SetupSessionsList(container);
|
||||
|
||||
AddSkip(container);
|
||||
AddDividerText(
|
||||
container,
|
||||
Lang::Viewer(lng_settings_sessions_about));
|
||||
}
|
||||
|
||||
void SetupExport(not_null<Ui::VerticalLayout*> container) {
|
||||
AddSkip(container);
|
||||
|
||||
AddButton(
|
||||
container,
|
||||
lng_settings_export_data,
|
||||
st::settingsButton
|
||||
)->addClickHandler([] {
|
||||
Ui::hideSettingsAndLayer();
|
||||
App::CallDelayed(
|
||||
st::boxDuration,
|
||||
&Auth(),
|
||||
[] { Auth().data().startExport(); });
|
||||
});
|
||||
|
||||
AddSkip(container);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
PrivacySecurity::PrivacySecurity(QWidget *parent, not_null<UserData*> self)
|
||||
: Section(parent)
|
||||
@ -24,7 +413,9 @@ PrivacySecurity::PrivacySecurity(QWidget *parent, not_null<UserData*> self)
|
||||
void PrivacySecurity::setupContent() {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
content->add(object_ptr<BoxContentDivider>(content));
|
||||
SetupPrivacy(content);
|
||||
SetupSecurity(content);
|
||||
SetupExport(content);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user