mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2026-07-25 06:54:43 +00:00
Move Advanced/Privacy/Chat settings to builder.
This commit is contained in:
@@ -1578,12 +1578,18 @@ PRIVATE
|
||||
settings/settings_local_passcode.h
|
||||
settings/settings_main.cpp
|
||||
settings/settings_main.h
|
||||
settings/builder/settings_advanced_builder.cpp
|
||||
settings/builder/settings_advanced_builder.h
|
||||
settings/builder/settings_builder.cpp
|
||||
settings/builder/settings_builder.h
|
||||
settings/builder/settings_chat_builder.cpp
|
||||
settings/builder/settings_chat_builder.h
|
||||
settings/builder/settings_main_builder.cpp
|
||||
settings/builder/settings_main_builder.h
|
||||
settings/builder/settings_notifications_builder.cpp
|
||||
settings/builder/settings_notifications_builder.h
|
||||
settings/builder/settings_privacy_security_builder.cpp
|
||||
settings/builder/settings_privacy_security_builder.h
|
||||
settings/settings_notifications.cpp
|
||||
settings/settings_notifications.h
|
||||
settings/settings_notifications_type.cpp
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "settings/settings_type.h"
|
||||
#include "settings/builder/settings_builder.h"
|
||||
|
||||
namespace Ui {
|
||||
class VerticalLayout;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Window {
|
||||
class SessionController;
|
||||
} // namespace Window
|
||||
|
||||
namespace Settings::Builder {
|
||||
|
||||
void AdvancedSection(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void(Type)> showOther,
|
||||
rpl::producer<> showFinished);
|
||||
|
||||
[[nodiscard]] std::vector<SearchEntry> AdvancedSectionForSearch();
|
||||
|
||||
} // namespace Settings::Builder
|
||||
@@ -7,9 +7,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "settings/builder/settings_builder.h"
|
||||
|
||||
#include "boxes/edit_privacy_box.h"
|
||||
#include "main/main_session.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "settings/settings_privacy_security.h"
|
||||
#include "ui/vertical_list.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/widgets/checkbox.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "window/window_session_controller.h"
|
||||
@@ -61,16 +65,17 @@ Ui::SettingsButton *SectionBuilder::addSettingsButton(ButtonArgs &&args) {
|
||||
auto highlight = std::move(args.highlight);
|
||||
const auto id = args.id;
|
||||
const auto button = v::match(_context, [&](const WidgetContext &ctx) -> Ui::SettingsButton* {
|
||||
const auto target = args.container ? args.container : ctx.container.get();
|
||||
if (args.label) {
|
||||
return AddButtonWithLabel(
|
||||
ctx.container,
|
||||
target,
|
||||
rpl::duplicate(args.title),
|
||||
std::move(args.label),
|
||||
st,
|
||||
std::move(args.icon));
|
||||
} else {
|
||||
return ctx.container->add(CreateButtonWithIcon(
|
||||
ctx.container,
|
||||
return target->add(CreateButtonWithIcon(
|
||||
target,
|
||||
rpl::duplicate(args.title),
|
||||
st,
|
||||
std::move(args.icon)));
|
||||
@@ -256,14 +261,51 @@ Ui::SettingsButton *SectionBuilder::addPremiumButton(PremiumButtonArgs &&args) {
|
||||
});
|
||||
}
|
||||
|
||||
Ui::SettingsButton *SectionBuilder::addPrivacyButton(PrivacyButtonArgs &&args) {
|
||||
const auto id = args.id;
|
||||
const auto premium = args.premium;
|
||||
auto title = std::move(args.title);
|
||||
return v::match(_context, [&](const WidgetContext &ctx)
|
||||
-> Ui::SettingsButton* {
|
||||
const auto button = AddPrivacyButton(
|
||||
ctx.controller,
|
||||
ctx.container,
|
||||
rpl::duplicate(title),
|
||||
{},
|
||||
args.key,
|
||||
std::move(args.controllerFactory));
|
||||
if (premium) {
|
||||
AddPrivacyPremiumStar(
|
||||
button,
|
||||
&ctx.controller->session(),
|
||||
rpl::duplicate(title),
|
||||
st::settingsButtonNoIcon.padding);
|
||||
}
|
||||
if (!id.isEmpty()) {
|
||||
registerHighlight(id, button, {});
|
||||
}
|
||||
return button;
|
||||
}, [&](const SearchContext &ctx) -> Ui::SettingsButton* {
|
||||
if (!args.id.isEmpty()) {
|
||||
ctx.entries->push_back({
|
||||
.id = std::move(args.id),
|
||||
.title = ResolveTitle(std::move(title)),
|
||||
.keywords = std::move(args.keywords),
|
||||
});
|
||||
}
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
Ui::SettingsButton *SectionBuilder::addToggle(ToggleArgs &&args) {
|
||||
auto highlight = std::move(args.highlight);
|
||||
const auto id = args.id;
|
||||
const auto button = v::match(_context, [&](const WidgetContext &ctx)
|
||||
-> Ui::SettingsButton* {
|
||||
const auto &st = args.st ? *args.st : st::settingsButton;
|
||||
const auto button = ctx.container->add(CreateButtonWithIcon(
|
||||
ctx.container,
|
||||
const auto target = args.container ? args.container : ctx.container.get();
|
||||
const auto button = target->add(CreateButtonWithIcon(
|
||||
target,
|
||||
rpl::duplicate(args.title),
|
||||
st,
|
||||
std::move(args.icon)));
|
||||
@@ -317,6 +359,77 @@ Ui::SlideWrap<Ui::SettingsButton> *SectionBuilder::addSlideToggle(
|
||||
});
|
||||
}
|
||||
|
||||
Ui::Checkbox *SectionBuilder::addCheckbox(CheckboxArgs &&args) {
|
||||
return v::match(_context, [&](const WidgetContext &ctx) -> Ui::Checkbox* {
|
||||
const auto checkbox = ctx.container->add(
|
||||
object_ptr<Ui::Checkbox>(
|
||||
ctx.container,
|
||||
ResolveTitle(rpl::duplicate(args.title)),
|
||||
args.checked,
|
||||
st::settingsCheckbox),
|
||||
st::settingsCheckboxPadding);
|
||||
return checkbox;
|
||||
}, [&](const SearchContext &ctx) -> Ui::Checkbox* {
|
||||
if (!args.id.isEmpty()) {
|
||||
ctx.entries->push_back({
|
||||
.id = std::move(args.id),
|
||||
.title = ResolveTitle(std::move(args.title)),
|
||||
.keywords = std::move(args.keywords),
|
||||
});
|
||||
}
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
Ui::SlideWrap<Ui::Checkbox> *SectionBuilder::addSlideCheckbox(
|
||||
SlideCheckboxArgs &&args) {
|
||||
return v::match(_context, [&](const WidgetContext &ctx)
|
||||
-> Ui::SlideWrap<Ui::Checkbox>* {
|
||||
const auto wrap = ctx.container->add(
|
||||
object_ptr<Ui::SlideWrap<Ui::Checkbox>>(
|
||||
ctx.container,
|
||||
object_ptr<Ui::Checkbox>(
|
||||
ctx.container,
|
||||
ResolveTitle(rpl::duplicate(args.title)),
|
||||
args.checked,
|
||||
st::settingsCheckbox),
|
||||
st::settingsCheckboxPadding));
|
||||
if (args.shown) {
|
||||
wrap->toggleOn(std::move(args.shown));
|
||||
}
|
||||
return wrap;
|
||||
}, [&](const SearchContext &ctx) -> Ui::SlideWrap<Ui::Checkbox>* {
|
||||
if (!args.id.isEmpty()) {
|
||||
ctx.entries->push_back({
|
||||
.id = std::move(args.id),
|
||||
.title = ResolveTitle(std::move(args.title)),
|
||||
.keywords = std::move(args.keywords),
|
||||
});
|
||||
}
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
Ui::SlideWrap<Ui::VerticalLayout> *SectionBuilder::addSlideSection(
|
||||
SlideSectionArgs &&args) {
|
||||
return v::match(_context, [&](const WidgetContext &ctx)
|
||||
-> Ui::SlideWrap<Ui::VerticalLayout>* {
|
||||
const auto wrap = ctx.container->add(
|
||||
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
|
||||
ctx.container,
|
||||
object_ptr<Ui::VerticalLayout>(ctx.container)));
|
||||
if (args.shown) {
|
||||
wrap->toggleOn(std::move(args.shown));
|
||||
}
|
||||
if (args.fill) {
|
||||
args.fill(wrap->entity());
|
||||
}
|
||||
return wrap;
|
||||
}, [](const SearchContext &) -> Ui::SlideWrap<Ui::VerticalLayout>* {
|
||||
return nullptr;
|
||||
});
|
||||
}
|
||||
|
||||
void SectionBuilder::addSubsectionTitle(rpl::producer<QString> text) {
|
||||
v::match(_context, [&](const WidgetContext &ctx) {
|
||||
AddSubsectionTitle(ctx.container, std::move(text));
|
||||
|
||||
@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "api/api_user_privacy.h"
|
||||
#include "base/object_ptr.h"
|
||||
#include "settings/settings_common.h"
|
||||
#include "settings/settings_type.h"
|
||||
@@ -14,10 +15,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
class EditPrivacyController;
|
||||
|
||||
namespace Ui {
|
||||
class RpWidget;
|
||||
class VerticalLayout;
|
||||
class SettingsButton;
|
||||
class Checkbox;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Window {
|
||||
@@ -80,6 +84,7 @@ public:
|
||||
rpl::producer<QString> title;
|
||||
const style::SettingsButton *st = nullptr;
|
||||
IconDescriptor icon;
|
||||
Ui::VerticalLayout *container = nullptr;
|
||||
rpl::producer<QString> label;
|
||||
Fn<void()> onClick;
|
||||
QStringList keywords;
|
||||
@@ -131,11 +136,22 @@ public:
|
||||
};
|
||||
Ui::SettingsButton *addPremiumButton(PremiumButtonArgs &&args);
|
||||
|
||||
struct PrivacyButtonArgs {
|
||||
QString id;
|
||||
rpl::producer<QString> title;
|
||||
Api::UserPrivacy::Key key;
|
||||
Fn<std::unique_ptr<EditPrivacyController>()> controllerFactory;
|
||||
bool premium = false;
|
||||
QStringList keywords;
|
||||
};
|
||||
Ui::SettingsButton *addPrivacyButton(PrivacyButtonArgs &&args);
|
||||
|
||||
struct ToggleArgs {
|
||||
QString id;
|
||||
rpl::producer<QString> title;
|
||||
const style::SettingsButton *st = nullptr;
|
||||
IconDescriptor icon;
|
||||
Ui::VerticalLayout *container = nullptr;
|
||||
rpl::producer<bool> toggled;
|
||||
QStringList keywords;
|
||||
HighlightDescriptor highlight;
|
||||
@@ -153,6 +169,29 @@ public:
|
||||
};
|
||||
Ui::SlideWrap<Ui::SettingsButton> *addSlideToggle(SlideToggleArgs &&args);
|
||||
|
||||
struct CheckboxArgs {
|
||||
QString id;
|
||||
rpl::producer<QString> title;
|
||||
bool checked = false;
|
||||
QStringList keywords;
|
||||
};
|
||||
Ui::Checkbox *addCheckbox(CheckboxArgs &&args);
|
||||
|
||||
struct SlideCheckboxArgs {
|
||||
QString id;
|
||||
rpl::producer<QString> title;
|
||||
bool checked = false;
|
||||
rpl::producer<bool> shown;
|
||||
QStringList keywords;
|
||||
};
|
||||
Ui::SlideWrap<Ui::Checkbox> *addSlideCheckbox(SlideCheckboxArgs &&args);
|
||||
|
||||
struct SlideSectionArgs {
|
||||
rpl::producer<bool> shown;
|
||||
Fn<void(not_null<Ui::VerticalLayout*>)> fill;
|
||||
};
|
||||
Ui::SlideWrap<Ui::VerticalLayout> *addSlideSection(SlideSectionArgs &&args);
|
||||
|
||||
void addSubsectionTitle(rpl::producer<QString> text);
|
||||
void addDivider();
|
||||
void addDividerText(rpl::producer<QString> text);
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
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/builder/settings_chat_builder.h"
|
||||
|
||||
#include "base/timer_rpl.h"
|
||||
#include "core/application.h"
|
||||
#include "core/core_settings.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "settings/builder/settings_builder.h"
|
||||
#include "settings/settings_chat.h"
|
||||
#include "settings/settings_experimental.h"
|
||||
#include "settings/settings_privacy_security.h"
|
||||
#include "settings/settings_shortcuts.h"
|
||||
#include "ui/vertical_list.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
#include "styles/style_settings.h"
|
||||
|
||||
namespace Settings::Builder {
|
||||
namespace {
|
||||
|
||||
void BuildChatSectionContent(
|
||||
SectionBuilder &builder,
|
||||
Window::SessionController *controller,
|
||||
Fn<void(Type)> showOther) {
|
||||
if (!controller) {
|
||||
builder.addSettingsButton({
|
||||
.id = u"appearance/theme"_q,
|
||||
.title = tr::lng_settings_themes(),
|
||||
.keywords = { u"theme"_q, u"color"_q, u"dark"_q, u"light"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"appearance/background"_q,
|
||||
.title = tr::lng_settings_bg_from_gallery(),
|
||||
.keywords = { u"background"_q, u"wallpaper"_q, u"image"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"appearance/quick_action"_q,
|
||||
.title = tr::lng_settings_quick_dialog_action_title(),
|
||||
.keywords = { u"swipe"_q, u"quick"_q, u"action"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"appearance/stickers"_q,
|
||||
.title = tr::lng_stickers_you_have(),
|
||||
.keywords = { u"stickers"_q, u"packs"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"appearance/emoji_sets"_q,
|
||||
.title = tr::lng_emoji_manage_sets(),
|
||||
.keywords = { u"emoji"_q, u"sets"_q, u"packs"_q },
|
||||
});
|
||||
builder.addCheckbox({
|
||||
.id = u"appearance/large_emoji"_q,
|
||||
.title = tr::lng_settings_large_emoji(),
|
||||
.checked = true,
|
||||
.keywords = { u"emoji"_q, u"large"_q, u"big"_q },
|
||||
});
|
||||
builder.addCheckbox({
|
||||
.id = u"appearance/replace_emoji"_q,
|
||||
.title = tr::lng_settings_replace_emojis(),
|
||||
.checked = true,
|
||||
.keywords = { u"emoji"_q, u"replace"_q, u"convert"_q },
|
||||
});
|
||||
builder.addCheckbox({
|
||||
.id = u"appearance/suggest_emoji"_q,
|
||||
.title = tr::lng_settings_suggest_emoji(),
|
||||
.checked = true,
|
||||
.keywords = { u"emoji"_q, u"suggest"_q, u"autocomplete"_q },
|
||||
});
|
||||
builder.addCheckbox({
|
||||
.id = u"appearance/suggest_stickers"_q,
|
||||
.title = tr::lng_settings_suggest_by_emoji(),
|
||||
.checked = true,
|
||||
.keywords = { u"stickers"_q, u"emoji"_q, u"suggest"_q },
|
||||
});
|
||||
builder.addCheckbox({
|
||||
.id = u"appearance/loop_stickers"_q,
|
||||
.title = tr::lng_settings_loop_stickers(),
|
||||
.checked = true,
|
||||
.keywords = { u"stickers"_q, u"loop"_q, u"animate"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"appearance/send_by_enter"_q,
|
||||
.title = tr::lng_settings_send_enter(),
|
||||
.keywords = { u"send"_q, u"enter"_q, u"message"_q },
|
||||
});
|
||||
builder.addToggle({
|
||||
.id = u"appearance/sensitive"_q,
|
||||
.title = tr::lng_settings_sensitive_disable_filtering(),
|
||||
.toggled = rpl::single(false),
|
||||
.keywords = { u"sensitive"_q, u"nsfw"_q, u"adult"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"data/shortcuts"_q,
|
||||
.title = tr::lng_settings_shortcuts(),
|
||||
.keywords = { u"shortcuts"_q, u"keyboard"_q, u"hotkeys"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"data/archive"_q,
|
||||
.title = tr::lng_context_archive_settings(),
|
||||
.keywords = { u"archive"_q, u"settings"_q },
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const auto container = builder.container();
|
||||
|
||||
auto updateOnTick = rpl::single(
|
||||
) | rpl::then(base::timer_each(60 * crl::time(1000)));
|
||||
|
||||
SetupThemeOptions(controller, container);
|
||||
SetupThemeSettings(controller, container);
|
||||
SetupCloudThemes(controller, container);
|
||||
SetupChatBackground(controller, container);
|
||||
SetupChatListQuickAction(controller, container);
|
||||
SetupStickersEmoji(controller, container);
|
||||
SetupMessages(controller, container);
|
||||
Ui::AddDivider(container);
|
||||
SetupSensitiveContent(controller, container, std::move(updateOnTick));
|
||||
SetupArchive(controller, container, showOther);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void ChatSection(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void(Type)> showOther,
|
||||
rpl::producer<> showFinished) {
|
||||
auto &lifetime = container->lifetime();
|
||||
const auto highlights = lifetime.make_state<HighlightRegistry>();
|
||||
|
||||
SectionBuilder builder(WidgetContext{
|
||||
.container = container,
|
||||
.controller = controller,
|
||||
.showOther = showOther,
|
||||
.isPaused = [] { return false; },
|
||||
.highlights = highlights,
|
||||
});
|
||||
|
||||
BuildChatSectionContent(builder, controller, showOther);
|
||||
|
||||
std::move(showFinished) | rpl::on_next([=] {
|
||||
for (const auto &[id, entry] : *highlights) {
|
||||
if (entry.widget) {
|
||||
controller->checkHighlightControl(
|
||||
id,
|
||||
entry.widget,
|
||||
base::duplicate(entry.args));
|
||||
}
|
||||
}
|
||||
}, lifetime);
|
||||
}
|
||||
|
||||
std::vector<SearchEntry> ChatSectionForSearch() {
|
||||
std::vector<SearchEntry> entries;
|
||||
SectionBuilder builder(SearchContext{ .entries = &entries });
|
||||
BuildChatSectionContent(builder, nullptr, nullptr);
|
||||
return entries;
|
||||
}
|
||||
|
||||
} // namespace Settings::Builder
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "settings/settings_type.h"
|
||||
#include "settings/builder/settings_builder.h"
|
||||
|
||||
namespace Ui {
|
||||
class VerticalLayout;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Window {
|
||||
class SessionController;
|
||||
} // namespace Window
|
||||
|
||||
namespace Settings::Builder {
|
||||
|
||||
void ChatSection(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void(Type)> showOther,
|
||||
rpl::producer<> showFinished);
|
||||
|
||||
[[nodiscard]] std::vector<SearchEntry> ChatSectionForSearch();
|
||||
|
||||
} // namespace Settings::Builder
|
||||
@@ -0,0 +1,726 @@
|
||||
/*
|
||||
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/builder/settings_privacy_security_builder.h"
|
||||
|
||||
#include "api/api_authorizations.h"
|
||||
#include "api/api_blocked_peers.h"
|
||||
#include "api/api_cloud_password.h"
|
||||
#include "api/api_global_privacy.h"
|
||||
#include "api/api_self_destruct.h"
|
||||
#include "api/api_sensitive_content.h"
|
||||
#include "api/api_user_privacy.h"
|
||||
#include "api/api_websites.h"
|
||||
#include "apiwrap.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "ui/chat/chat_style.h"
|
||||
#include "base/timer_rpl.h"
|
||||
#include "boxes/edit_privacy_box.h"
|
||||
#include "boxes/self_destruction_box.h"
|
||||
#include "core/application.h"
|
||||
#include "core/core_cloud_password.h"
|
||||
#include "core/core_settings.h"
|
||||
#include "data/components/passkeys.h"
|
||||
#include "data/components/top_peers.h"
|
||||
#include "data/data_peer_values.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_domain.h"
|
||||
#include "main/main_session.h"
|
||||
#include "platform/platform_webauthn.h"
|
||||
#include "settings/builder/settings_builder.h"
|
||||
#include "settings/cloud_password/settings_cloud_password_email_confirm.h"
|
||||
#include "settings/cloud_password/settings_cloud_password_input.h"
|
||||
#include "settings/cloud_password/settings_cloud_password_start.h"
|
||||
#include "settings/settings_active_sessions.h"
|
||||
#include "settings/settings_blocked_peers.h"
|
||||
#include "settings/settings_global_ttl.h"
|
||||
#include "settings/settings_local_passcode.h"
|
||||
#include "settings/settings_passkeys.h"
|
||||
#include "settings/settings_privacy_controllers.h"
|
||||
#include "settings/settings_privacy_security.h"
|
||||
#include "settings/settings_websites.h"
|
||||
#include "storage/storage_domain.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/text/format_values.h"
|
||||
#include "ui/vertical_list.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "ui/wrap/vertical_layout.h"
|
||||
#include "window/window_session_controller.h"
|
||||
#include "styles/style_menu_icons.h"
|
||||
#include "styles/style_settings.h"
|
||||
|
||||
namespace Settings::Builder {
|
||||
namespace {
|
||||
|
||||
constexpr auto kUpdateTimeout = 60 * crl::time(1000);
|
||||
|
||||
using Privacy = Api::UserPrivacy;
|
||||
|
||||
void BuildSecuritySection(
|
||||
SectionBuilder &builder,
|
||||
not_null<Window::SessionController*> controller,
|
||||
rpl::producer<> updateTrigger,
|
||||
Fn<void(Type)> showOther) {
|
||||
const auto session = &controller->session();
|
||||
|
||||
builder.addSkip(st::settingsPrivacySkip);
|
||||
builder.addSubsectionTitle(tr::lng_settings_security());
|
||||
|
||||
using State = Core::CloudPasswordState;
|
||||
enum class PasswordState {
|
||||
Loading,
|
||||
On,
|
||||
Off,
|
||||
Unconfirmed,
|
||||
};
|
||||
auto passwordState = rpl::single(
|
||||
PasswordState::Loading
|
||||
) | rpl::then(session->api().cloudPassword().state(
|
||||
) | rpl::map([](const State &state) {
|
||||
return (!state.unconfirmedPattern.isEmpty())
|
||||
? PasswordState::Unconfirmed
|
||||
: state.hasPassword
|
||||
? PasswordState::On
|
||||
: PasswordState::Off;
|
||||
})) | rpl::distinct_until_changed();
|
||||
|
||||
auto cloudPasswordLabel = rpl::duplicate(
|
||||
passwordState
|
||||
) | rpl::map([=](PasswordState state) {
|
||||
return (state == PasswordState::Loading)
|
||||
? tr::lng_profile_loading(tr::now)
|
||||
: (state == PasswordState::On)
|
||||
? tr::lng_settings_cloud_password_on(tr::now)
|
||||
: tr::lng_settings_cloud_password_off(tr::now);
|
||||
});
|
||||
|
||||
builder.addSettingsButton({
|
||||
.id = u"security/cloud_password"_q,
|
||||
.title = tr::lng_settings_cloud_password_start_title(),
|
||||
.icon = { &st::menuIcon2SV },
|
||||
.label = std::move(cloudPasswordLabel),
|
||||
.onClick = [=, passwordState = base::duplicate(passwordState)] {
|
||||
const auto state = rpl::variable<PasswordState>(
|
||||
base::duplicate(passwordState)).current();
|
||||
if (state == PasswordState::Loading) {
|
||||
return;
|
||||
} else if (state == PasswordState::On) {
|
||||
showOther(CloudPasswordInputId());
|
||||
} else if (state == PasswordState::Off) {
|
||||
showOther(CloudPasswordStartId());
|
||||
} else if (state == PasswordState::Unconfirmed) {
|
||||
showOther(CloudPasswordEmailConfirmId());
|
||||
}
|
||||
},
|
||||
.keywords = { u"password"_q, u"2fa"_q, u"two-factor"_q },
|
||||
});
|
||||
|
||||
session->api().cloudPassword().reload();
|
||||
|
||||
auto ttlLabel = rpl::combine(
|
||||
session->api().selfDestruct().periodDefaultHistoryTTL(),
|
||||
tr::lng_settings_ttl_after_off()
|
||||
) | rpl::map([](int ttl, const QString &none) {
|
||||
return ttl ? Ui::FormatTTL(ttl) : none;
|
||||
});
|
||||
|
||||
builder.addSettingsButton({
|
||||
.id = u"security/ttl"_q,
|
||||
.title = tr::lng_settings_ttl_title(),
|
||||
.icon = { &st::menuIconTTL },
|
||||
.label = std::move(ttlLabel),
|
||||
.onClick = [showOther] {
|
||||
showOther(GlobalTTLId());
|
||||
},
|
||||
.keywords = { u"ttl"_q, u"auto-delete"_q, u"timer"_q },
|
||||
});
|
||||
|
||||
rpl::duplicate(
|
||||
updateTrigger
|
||||
) | rpl::on_next([=] {
|
||||
session->api().selfDestruct().reload();
|
||||
}, builder.container()->lifetime());
|
||||
|
||||
auto passcodeHas = rpl::single(rpl::empty) | rpl::then(
|
||||
session->domain().local().localPasscodeChanged()
|
||||
) | rpl::map([=] {
|
||||
return session->domain().local().hasLocalPasscode();
|
||||
});
|
||||
auto passcodeLabel = rpl::combine(
|
||||
tr::lng_settings_cloud_password_on(),
|
||||
tr::lng_settings_cloud_password_off(),
|
||||
rpl::duplicate(passcodeHas)
|
||||
) | rpl::map([](const QString &on, const QString &off, bool has) {
|
||||
return has ? on : off;
|
||||
});
|
||||
|
||||
builder.addSettingsButton({
|
||||
.id = u"security/passcode"_q,
|
||||
.title = tr::lng_settings_passcode_title(),
|
||||
.icon = { &st::menuIconLock },
|
||||
.label = std::move(passcodeLabel),
|
||||
.onClick = [=, passcodeHas = std::move(passcodeHas)]() mutable {
|
||||
if (rpl::variable<bool>(std::move(passcodeHas)).current()) {
|
||||
showOther(LocalPasscodeCheckId());
|
||||
} else {
|
||||
showOther(LocalPasscodeCreateId());
|
||||
}
|
||||
},
|
||||
.keywords = { u"passcode"_q, u"lock"_q, u"pin"_q },
|
||||
});
|
||||
|
||||
if (session->passkeys().possible()) {
|
||||
auto passkeysLabel = rpl::combine(
|
||||
tr::lng_profile_loading(),
|
||||
(rpl::single(rpl::empty_value())
|
||||
| rpl::then(session->passkeys().requestList())) | rpl::map([=] {
|
||||
return session->passkeys().list().size();
|
||||
})
|
||||
) | rpl::map([=](const QString &loading, int count) {
|
||||
return !session->passkeys().listKnown()
|
||||
? loading
|
||||
: count == 1
|
||||
? session->passkeys().list().front().name
|
||||
: count
|
||||
? QString::number(count)
|
||||
: tr::lng_settings_cloud_password_off(tr::now);
|
||||
});
|
||||
|
||||
auto passkeysShown = (rpl::single(rpl::empty_value())
|
||||
| rpl::then(session->passkeys().requestList())) | rpl::map([=] {
|
||||
return Platform::WebAuthn::IsSupported()
|
||||
|| !session->passkeys().list().empty();
|
||||
});
|
||||
|
||||
builder.addSlideLabeledButton({
|
||||
.id = u"security/passkeys"_q,
|
||||
.title = tr::lng_settings_passkeys_title(),
|
||||
.icon = { &st::menuIconPermissions },
|
||||
.label = std::move(passkeysLabel),
|
||||
.shown = std::move(passkeysShown),
|
||||
.onClick = [=] {
|
||||
if (!session->passkeys().listKnown()) {
|
||||
return;
|
||||
}
|
||||
const auto count = session->passkeys().list().size();
|
||||
if (count == 0) {
|
||||
controller->show(Box([=](not_null<Ui::GenericBox*> box) {
|
||||
PasskeysNoneBox(box, session);
|
||||
box->boxClosing() | rpl::on_next([=] {
|
||||
if (session->passkeys().list().size()) {
|
||||
controller->showSettings(PasskeysId());
|
||||
}
|
||||
}, box->lifetime());
|
||||
}));
|
||||
} else {
|
||||
controller->showSettings(PasskeysId());
|
||||
}
|
||||
},
|
||||
.keywords = { u"passkeys"_q, u"biometric"_q },
|
||||
});
|
||||
}
|
||||
|
||||
auto blockedCount = rpl::combine(
|
||||
session->api().blockedPeers().slice(
|
||||
) | rpl::map([](const Api::BlockedPeers::Slice &data) {
|
||||
return data.total;
|
||||
}),
|
||||
tr::lng_settings_no_blocked_users()
|
||||
) | rpl::map([](int count, const QString &none) {
|
||||
return count ? QString::number(count) : none;
|
||||
});
|
||||
|
||||
builder.addSettingsButton({
|
||||
.id = u"security/blocked"_q,
|
||||
.title = tr::lng_settings_blocked_users(),
|
||||
.icon = { &st::menuIconBlock },
|
||||
.label = std::move(blockedCount),
|
||||
.onClick = [=] {
|
||||
showOther(Blocked::Id());
|
||||
},
|
||||
.keywords = { u"blocked"_q, u"ban"_q },
|
||||
});
|
||||
|
||||
rpl::duplicate(
|
||||
updateTrigger
|
||||
) | rpl::on_next([=] {
|
||||
session->api().blockedPeers().reload();
|
||||
}, builder.container()->lifetime());
|
||||
|
||||
auto websitesCount = session->api().websites().totalValue();
|
||||
auto websitesShown = rpl::duplicate(websitesCount) | rpl::map(
|
||||
rpl::mappers::_1 > 0);
|
||||
auto websitesLabel = rpl::duplicate(
|
||||
websitesCount
|
||||
) | rpl::filter(rpl::mappers::_1 > 0) | rpl::map([](int count) {
|
||||
return QString::number(count);
|
||||
});
|
||||
|
||||
builder.addSlideLabeledButton({
|
||||
.id = u"security/websites"_q,
|
||||
.title = tr::lng_settings_logged_in(),
|
||||
.icon = { &st::menuIconIpAddress },
|
||||
.label = std::move(websitesLabel),
|
||||
.shown = std::move(websitesShown),
|
||||
.onClick = [=] {
|
||||
showOther(Websites::Id());
|
||||
},
|
||||
.keywords = { u"websites"_q, u"bots"_q, u"logged"_q },
|
||||
});
|
||||
|
||||
rpl::duplicate(
|
||||
updateTrigger
|
||||
) | rpl::on_next([=] {
|
||||
session->api().websites().reload();
|
||||
}, builder.container()->lifetime());
|
||||
|
||||
auto sessionsCount = session->api().authorizations().totalValue(
|
||||
) | rpl::map([](int count) {
|
||||
return count ? QString::number(count) : QString();
|
||||
});
|
||||
|
||||
builder.addSettingsButton({
|
||||
.id = u"security/sessions"_q,
|
||||
.title = tr::lng_settings_show_sessions(),
|
||||
.icon = { &st::menuIconDevices },
|
||||
.label = std::move(sessionsCount),
|
||||
.onClick = [=] {
|
||||
showOther(Sessions::Id());
|
||||
},
|
||||
.keywords = { u"sessions"_q, u"devices"_q, u"active"_q },
|
||||
});
|
||||
|
||||
std::move(
|
||||
updateTrigger
|
||||
) | rpl::on_next([=] {
|
||||
session->api().authorizations().reload();
|
||||
}, builder.container()->lifetime());
|
||||
|
||||
builder.addSkip();
|
||||
builder.addDividerText(tr::lng_settings_sessions_about());
|
||||
}
|
||||
|
||||
void BuildPrivacySection(
|
||||
SectionBuilder &builder,
|
||||
not_null<Window::SessionController*> controller) {
|
||||
const auto session = &controller->session();
|
||||
|
||||
builder.addSkip(st::settingsPrivacySkip);
|
||||
builder.addSubsectionTitle(tr::lng_settings_privacy_title());
|
||||
|
||||
using Key = Privacy::Key;
|
||||
|
||||
builder.addPrivacyButton({
|
||||
.id = u"privacy/phone_number"_q,
|
||||
.title = tr::lng_settings_phone_number_privacy(),
|
||||
.key = Key::PhoneNumber,
|
||||
.controllerFactory = [=] {
|
||||
return std::make_unique<PhoneNumberPrivacyController>(controller);
|
||||
},
|
||||
.keywords = { u"phone"_q, u"number"_q },
|
||||
});
|
||||
|
||||
builder.addPrivacyButton({
|
||||
.id = u"privacy/last_seen"_q,
|
||||
.title = tr::lng_settings_last_seen(),
|
||||
.key = Key::LastSeen,
|
||||
.controllerFactory = [=] {
|
||||
return std::make_unique<LastSeenPrivacyController>(session);
|
||||
},
|
||||
.keywords = { u"last seen"_q, u"online"_q },
|
||||
});
|
||||
|
||||
builder.addPrivacyButton({
|
||||
.id = u"privacy/profile_photo"_q,
|
||||
.title = tr::lng_settings_profile_photo_privacy(),
|
||||
.key = Key::ProfilePhoto,
|
||||
.controllerFactory = [] {
|
||||
return std::make_unique<ProfilePhotoPrivacyController>();
|
||||
},
|
||||
.keywords = { u"photo"_q, u"avatar"_q },
|
||||
});
|
||||
|
||||
builder.addPrivacyButton({
|
||||
.id = u"privacy/forwards"_q,
|
||||
.title = tr::lng_settings_forwards_privacy(),
|
||||
.key = Key::Forwards,
|
||||
.controllerFactory = [=] {
|
||||
return std::make_unique<ForwardsPrivacyController>(controller);
|
||||
},
|
||||
.keywords = { u"forwards"_q, u"link"_q },
|
||||
});
|
||||
|
||||
builder.addPrivacyButton({
|
||||
.id = u"privacy/calls"_q,
|
||||
.title = tr::lng_settings_calls(),
|
||||
.key = Key::Calls,
|
||||
.controllerFactory = [] {
|
||||
return std::make_unique<CallsPrivacyController>();
|
||||
},
|
||||
.keywords = { u"calls"_q, u"voice"_q },
|
||||
});
|
||||
|
||||
builder.addPrivacyButton({
|
||||
.id = u"privacy/voices"_q,
|
||||
.title = tr::lng_settings_voices_privacy(),
|
||||
.key = Key::Voices,
|
||||
.controllerFactory = [=] {
|
||||
return std::make_unique<VoicesPrivacyController>(session);
|
||||
},
|
||||
.premium = true,
|
||||
.keywords = { u"voice"_q, u"messages"_q },
|
||||
});
|
||||
|
||||
const auto privacy = &session->api().globalPrivacy();
|
||||
auto messagesLabel = rpl::combine(
|
||||
privacy->newRequirePremium(),
|
||||
privacy->newChargeStars()
|
||||
) | rpl::map([=](bool requirePremium, int chargeStars) {
|
||||
return chargeStars
|
||||
? tr::lng_edit_privacy_paid()
|
||||
: requirePremium
|
||||
? tr::lng_edit_privacy_contacts_and_premium()
|
||||
: tr::lng_edit_privacy_everyone();
|
||||
}) | rpl::flatten_latest();
|
||||
|
||||
const auto messagesPremium = !session->appConfig().newRequirePremiumFree();
|
||||
const auto messagesButton = builder.addSettingsButton({
|
||||
.id = u"privacy/messages"_q,
|
||||
.title = tr::lng_settings_messages_privacy(),
|
||||
.st = &st::settingsButtonNoIcon,
|
||||
.label = rpl::duplicate(messagesLabel),
|
||||
.onClick = [=] {
|
||||
controller->show(Box(EditMessagesPrivacyBox, controller));
|
||||
},
|
||||
.keywords = { u"messages"_q, u"new"_q, u"unknown"_q },
|
||||
});
|
||||
if (messagesPremium && messagesButton) {
|
||||
AddPrivacyPremiumStar(
|
||||
messagesButton,
|
||||
session,
|
||||
std::move(messagesLabel),
|
||||
st::settingsButtonNoIcon.padding);
|
||||
}
|
||||
|
||||
builder.addPrivacyButton({
|
||||
.id = u"privacy/birthday"_q,
|
||||
.title = tr::lng_settings_birthday_privacy(),
|
||||
.key = Key::Birthday,
|
||||
.controllerFactory = [] {
|
||||
return std::make_unique<BirthdayPrivacyController>();
|
||||
},
|
||||
.keywords = { u"birthday"_q, u"age"_q },
|
||||
});
|
||||
|
||||
builder.addPrivacyButton({
|
||||
.id = u"privacy/gifts"_q,
|
||||
.title = tr::lng_settings_gifts_privacy(),
|
||||
.key = Key::GiftsAutoSave,
|
||||
.controllerFactory = [] {
|
||||
return std::make_unique<GiftsAutoSavePrivacyController>();
|
||||
},
|
||||
.keywords = { u"gifts"_q },
|
||||
});
|
||||
|
||||
builder.addPrivacyButton({
|
||||
.id = u"privacy/bio"_q,
|
||||
.title = tr::lng_settings_bio_privacy(),
|
||||
.key = Key::About,
|
||||
.controllerFactory = [] {
|
||||
return std::make_unique<AboutPrivacyController>();
|
||||
},
|
||||
.keywords = { u"bio"_q, u"about"_q },
|
||||
});
|
||||
|
||||
builder.addPrivacyButton({
|
||||
.id = u"privacy/saved_music"_q,
|
||||
.title = tr::lng_settings_saved_music_privacy(),
|
||||
.key = Key::SavedMusic,
|
||||
.controllerFactory = [] {
|
||||
return std::make_unique<SavedMusicPrivacyController>();
|
||||
},
|
||||
.keywords = { u"music"_q, u"saved"_q },
|
||||
});
|
||||
|
||||
builder.addPrivacyButton({
|
||||
.id = u"privacy/groups"_q,
|
||||
.title = tr::lng_settings_groups_invite(),
|
||||
.key = Key::Invites,
|
||||
.controllerFactory = [] {
|
||||
return std::make_unique<GroupsInvitePrivacyController>();
|
||||
},
|
||||
.keywords = { u"groups"_q, u"invite"_q },
|
||||
});
|
||||
|
||||
session->api().userPrivacy().reload(Privacy::Key::AddedByPhone);
|
||||
|
||||
builder.addSkip(st::settingsPrivacySecurityPadding);
|
||||
builder.addDivider();
|
||||
}
|
||||
|
||||
void BuildArchiveAndMuteSection(
|
||||
SectionBuilder &builder,
|
||||
not_null<Window::SessionController*> controller) {
|
||||
SetupArchiveAndMute(controller, builder.container());
|
||||
}
|
||||
|
||||
void BuildBotsAndWebsitesSection(
|
||||
SectionBuilder &builder,
|
||||
not_null<Window::SessionController*> controller) {
|
||||
SetupBotsAndWebsites(controller, builder.container());
|
||||
}
|
||||
|
||||
void BuildTopPeersSection(
|
||||
SectionBuilder &builder,
|
||||
not_null<Window::SessionController*> controller) {
|
||||
const auto session = &controller->session();
|
||||
|
||||
builder.addSkip();
|
||||
builder.addSubsectionTitle(tr::lng_settings_top_peers_title());
|
||||
|
||||
const auto toggle = builder.addToggle({
|
||||
.id = u"privacy/top_peers"_q,
|
||||
.title = tr::lng_settings_top_peers_suggest(),
|
||||
.st = &st::settingsButtonNoIcon,
|
||||
.toggled = rpl::single(
|
||||
rpl::empty
|
||||
) | rpl::then(
|
||||
session->topPeers().updates()
|
||||
) | rpl::map([=] {
|
||||
return !session->topPeers().disabled();
|
||||
}),
|
||||
.keywords = { u"suggest"_q, u"contacts"_q },
|
||||
});
|
||||
|
||||
if (toggle) {
|
||||
toggle->toggledChanges(
|
||||
) | rpl::filter([=](bool enabled) {
|
||||
return enabled == session->topPeers().disabled();
|
||||
}) | rpl::on_next([=](bool enabled) {
|
||||
session->topPeers().toggleDisabled(!enabled);
|
||||
}, builder.container()->lifetime());
|
||||
}
|
||||
|
||||
builder.addSkip();
|
||||
builder.addDividerText(tr::lng_settings_top_peers_about());
|
||||
}
|
||||
|
||||
void BuildSelfDestructionSection(
|
||||
SectionBuilder &builder,
|
||||
not_null<Window::SessionController*> controller,
|
||||
rpl::producer<> updateTrigger) {
|
||||
const auto session = &controller->session();
|
||||
|
||||
builder.addSkip();
|
||||
builder.addSubsectionTitle(tr::lng_settings_destroy_title());
|
||||
|
||||
std::move(
|
||||
updateTrigger
|
||||
) | rpl::on_next([=] {
|
||||
session->api().selfDestruct().reload();
|
||||
}, builder.container()->lifetime());
|
||||
|
||||
auto label = session->api().selfDestruct().daysAccountTTL(
|
||||
) | rpl::map(SelfDestructionBox::DaysLabel);
|
||||
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/self_destruct"_q,
|
||||
.title = tr::lng_settings_destroy_if(),
|
||||
.st = &st::settingsButtonNoIcon,
|
||||
.label = std::move(label),
|
||||
.onClick = [=] {
|
||||
controller->show(Box<SelfDestructionBox>(
|
||||
session,
|
||||
SelfDestructionBox::Type::Account,
|
||||
session->api().selfDestruct().daysAccountTTL()));
|
||||
},
|
||||
.keywords = { u"delete"_q, u"destroy"_q, u"inactive"_q },
|
||||
});
|
||||
|
||||
builder.addSkip();
|
||||
}
|
||||
|
||||
void BuildPrivacySecuritySectionContent(
|
||||
SectionBuilder &builder,
|
||||
Window::SessionController *controller,
|
||||
Fn<void(Type)> showOther) {
|
||||
if (!controller) {
|
||||
builder.addSettingsButton({
|
||||
.id = u"security/cloud_password"_q,
|
||||
.title = tr::lng_settings_cloud_password_start_title(),
|
||||
.keywords = { u"password"_q, u"2fa"_q, u"two-factor"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"security/ttl"_q,
|
||||
.title = tr::lng_settings_ttl_title(),
|
||||
.keywords = { u"ttl"_q, u"auto-delete"_q, u"timer"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"security/passcode"_q,
|
||||
.title = tr::lng_settings_passcode_title(),
|
||||
.keywords = { u"passcode"_q, u"lock"_q, u"pin"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"security/passkeys"_q,
|
||||
.title = tr::lng_settings_passkeys_title(),
|
||||
.keywords = { u"passkeys"_q, u"biometric"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"security/blocked"_q,
|
||||
.title = tr::lng_settings_blocked_users(),
|
||||
.keywords = { u"blocked"_q, u"ban"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"security/websites"_q,
|
||||
.title = tr::lng_settings_logged_in(),
|
||||
.keywords = { u"websites"_q, u"bots"_q, u"logged"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"security/sessions"_q,
|
||||
.title = tr::lng_settings_show_sessions(),
|
||||
.keywords = { u"sessions"_q, u"devices"_q, u"active"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/phone_number"_q,
|
||||
.title = tr::lng_settings_phone_number_privacy(),
|
||||
.keywords = { u"phone"_q, u"number"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/last_seen"_q,
|
||||
.title = tr::lng_settings_last_seen(),
|
||||
.keywords = { u"last seen"_q, u"online"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/profile_photo"_q,
|
||||
.title = tr::lng_settings_profile_photo_privacy(),
|
||||
.keywords = { u"photo"_q, u"avatar"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/forwards"_q,
|
||||
.title = tr::lng_settings_forwards_privacy(),
|
||||
.keywords = { u"forwards"_q, u"link"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/calls"_q,
|
||||
.title = tr::lng_settings_calls(),
|
||||
.keywords = { u"calls"_q, u"voice"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/voices"_q,
|
||||
.title = tr::lng_settings_voices_privacy(),
|
||||
.keywords = { u"voice"_q, u"messages"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/messages"_q,
|
||||
.title = tr::lng_settings_messages_privacy(),
|
||||
.keywords = { u"messages"_q, u"new"_q, u"unknown"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/birthday"_q,
|
||||
.title = tr::lng_settings_birthday_privacy(),
|
||||
.keywords = { u"birthday"_q, u"age"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/gifts"_q,
|
||||
.title = tr::lng_settings_gifts_privacy(),
|
||||
.keywords = { u"gifts"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/bio"_q,
|
||||
.title = tr::lng_settings_bio_privacy(),
|
||||
.keywords = { u"bio"_q, u"about"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/saved_music"_q,
|
||||
.title = tr::lng_settings_saved_music_privacy(),
|
||||
.keywords = { u"music"_q, u"saved"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/groups"_q,
|
||||
.title = tr::lng_settings_groups_invite(),
|
||||
.keywords = { u"groups"_q, u"invite"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/archive_and_mute"_q,
|
||||
.title = tr::lng_settings_auto_archive(),
|
||||
.keywords = { u"archive"_q, u"mute"_q, u"new"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/bots_payment"_q,
|
||||
.title = tr::lng_settings_clear_payment_info(),
|
||||
.keywords = { u"bots"_q, u"payment"_q, u"clear"_q },
|
||||
});
|
||||
builder.addToggle({
|
||||
.id = u"privacy/top_peers"_q,
|
||||
.title = tr::lng_settings_top_peers_suggest(),
|
||||
.toggled = rpl::single(true),
|
||||
.keywords = { u"suggest"_q, u"contacts"_q },
|
||||
});
|
||||
builder.addSettingsButton({
|
||||
.id = u"privacy/self_destruct"_q,
|
||||
.title = tr::lng_settings_destroy_if(),
|
||||
.keywords = { u"delete"_q, u"destroy"_q, u"inactive"_q },
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
auto updateOnTick = rpl::single(
|
||||
) | rpl::then(base::timer_each(kUpdateTimeout));
|
||||
const auto trigger = [&] {
|
||||
return rpl::duplicate(updateOnTick);
|
||||
};
|
||||
|
||||
BuildSecuritySection(builder, controller, trigger(), showOther);
|
||||
BuildPrivacySection(builder, controller);
|
||||
BuildArchiveAndMuteSection(builder, controller);
|
||||
BuildBotsAndWebsitesSection(builder, controller);
|
||||
SetupConfirmationExtensions(controller, builder.container());
|
||||
BuildTopPeersSection(builder, controller);
|
||||
BuildSelfDestructionSection(builder, controller, trigger());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void PrivacySecuritySection(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void(Type)> showOther,
|
||||
rpl::producer<> showFinished) {
|
||||
auto &lifetime = container->lifetime();
|
||||
const auto highlights = lifetime.make_state<HighlightRegistry>();
|
||||
|
||||
SectionBuilder builder(WidgetContext{
|
||||
.container = container,
|
||||
.controller = controller,
|
||||
.showOther = showOther,
|
||||
.isPaused = [] { return false; },
|
||||
.highlights = highlights,
|
||||
});
|
||||
|
||||
BuildPrivacySecuritySectionContent(builder, controller, showOther);
|
||||
|
||||
std::move(showFinished) | rpl::on_next([=] {
|
||||
for (const auto &[id, entry] : *highlights) {
|
||||
if (entry.widget) {
|
||||
controller->checkHighlightControl(
|
||||
id,
|
||||
entry.widget,
|
||||
base::duplicate(entry.args));
|
||||
}
|
||||
}
|
||||
}, lifetime);
|
||||
}
|
||||
|
||||
std::vector<SearchEntry> PrivacySecuritySectionForSearch() {
|
||||
std::vector<SearchEntry> entries;
|
||||
SectionBuilder builder(SearchContext{ .entries = &entries });
|
||||
BuildPrivacySecuritySectionContent(builder, nullptr, nullptr);
|
||||
return entries;
|
||||
}
|
||||
|
||||
} // namespace Settings::Builder
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
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
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "settings/settings_type.h"
|
||||
#include "settings/builder/settings_builder.h"
|
||||
|
||||
namespace Ui {
|
||||
class VerticalLayout;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Window {
|
||||
class SessionController;
|
||||
} // namespace Window
|
||||
|
||||
namespace Settings::Builder {
|
||||
|
||||
void PrivacySecuritySection(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void(Type)> showOther,
|
||||
rpl::producer<> showFinished);
|
||||
|
||||
[[nodiscard]] std::vector<SearchEntry> PrivacySecuritySectionForSearch();
|
||||
|
||||
} // namespace Settings::Builder
|
||||
@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "settings/settings_advanced.h"
|
||||
|
||||
#include "settings/builder/settings_advanced_builder.h"
|
||||
#include "api/api_global_privacy.h"
|
||||
#include "apiwrap.h"
|
||||
#include "settings/settings_chat.h"
|
||||
@@ -1044,56 +1045,8 @@ rpl::producer<QString> Advanced::title() {
|
||||
void Advanced::setupContent(not_null<Window::SessionController*> controller) {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
auto empty = true;
|
||||
const auto addDivider = [&] {
|
||||
if (empty) {
|
||||
empty = false;
|
||||
} else {
|
||||
AddDivider(content);
|
||||
}
|
||||
};
|
||||
const auto addUpdate = [&] {
|
||||
if (HasUpdate()) {
|
||||
addDivider();
|
||||
AddSkip(content);
|
||||
AddSubsectionTitle(content, tr::lng_settings_version_info());
|
||||
SetupUpdate(content);
|
||||
AddSkip(content);
|
||||
}
|
||||
};
|
||||
if (!cAutoUpdate()) {
|
||||
addUpdate();
|
||||
}
|
||||
addDivider();
|
||||
SetupDataStorage(controller, content);
|
||||
SetupAutoDownload(controller, content);
|
||||
SetupWindowTitle(controller, content);
|
||||
SetupWindowCloseBehavior(controller, content);
|
||||
SetupSystemIntegration(controller, content);
|
||||
empty = false;
|
||||
|
||||
AddDivider(content);
|
||||
AddSkip(content);
|
||||
AddSubsectionTitle(content, tr::lng_settings_performance());
|
||||
SetupPerformance(controller, content);
|
||||
AddSkip(content);
|
||||
|
||||
if (HasSystemSpellchecker()) {
|
||||
AddDivider(content);
|
||||
AddSkip(content);
|
||||
AddSubsectionTitle(content, tr::lng_settings_spellchecker());
|
||||
SetupSpellchecker(controller, content);
|
||||
AddSkip(content);
|
||||
}
|
||||
|
||||
if (cAutoUpdate()) {
|
||||
addUpdate();
|
||||
}
|
||||
|
||||
AddSkip(content);
|
||||
AddDivider(content);
|
||||
AddSkip(content);
|
||||
SetupExport(controller, content, showOtherMethod());
|
||||
setController(controller);
|
||||
build(content, Builder::AdvancedSection);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include "settings/settings_chat.h"
|
||||
|
||||
#include "base/timer_rpl.h"
|
||||
#include "settings/builder/settings_chat_builder.h"
|
||||
#include "settings/settings_advanced.h"
|
||||
#include "settings/settings_privacy_security.h"
|
||||
#include "settings/settings_experimental.h"
|
||||
@@ -2039,19 +2040,8 @@ void Chat::fillTopBarMenu(const Ui::Menu::MenuCallback &addAction) {
|
||||
void Chat::setupContent(not_null<Window::SessionController*> controller) {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
auto updateOnTick = rpl::single(
|
||||
) | rpl::then(base::timer_each(60 * crl::time(1000)));
|
||||
|
||||
SetupThemeOptions(controller, content);
|
||||
SetupThemeSettings(controller, content);
|
||||
SetupCloudThemes(controller, content);
|
||||
SetupChatBackground(controller, content);
|
||||
SetupChatListQuickAction(controller, content);
|
||||
SetupStickersEmoji(controller, content);
|
||||
SetupMessages(controller, content);
|
||||
Ui::AddDivider(content);
|
||||
SetupSensitiveContent(controller, content, std::move(updateOnTick));
|
||||
SetupArchive(controller, content, showOtherMethod());
|
||||
setController(controller);
|
||||
build(content, Builder::ChatSection);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,44 @@ void PaintRoundColorButton(
|
||||
QBrush brush,
|
||||
float64 selected);
|
||||
|
||||
void SetupThemeOptions(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
void SetupThemeSettings(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
void SetupCloudThemes(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
void SetupChatBackground(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
void SetupChatListQuickAction(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
void SetupStickersEmoji(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
void SetupMessages(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
void SetupArchive(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
Fn<void(Type)> showOther);
|
||||
|
||||
void SetupSensitiveContent(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<> updateTrigger);
|
||||
|
||||
class Chat : public Section<Chat> {
|
||||
public:
|
||||
Chat(QWidget *parent, not_null<Window::SessionController*> controller);
|
||||
|
||||
@@ -285,6 +285,19 @@ void ScrollToWidget(not_null<QWidget*> target) {
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractSection::build(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
SectionBuilder builder) {
|
||||
builder(
|
||||
static_cast<Ui::VerticalLayout*>(container->add(
|
||||
object_ptr<Ui::OverrideMargins>(
|
||||
container,
|
||||
object_ptr<Ui::VerticalLayout>(container)))->entity()),
|
||||
_controller,
|
||||
showOtherMethod(),
|
||||
_showFinished.events());
|
||||
}
|
||||
|
||||
Icon::Icon(IconDescriptor descriptor) : _icon(descriptor.icon) {
|
||||
const auto background = [&]() -> const style::color* {
|
||||
if (descriptor.type == IconType::Simple) {
|
||||
|
||||
@@ -88,13 +88,19 @@ struct HighlightDescriptor {
|
||||
void HighlightWidget(QWidget *target, HighlightArgs &&args = {});
|
||||
void ScrollToWidget(not_null<QWidget*> target);
|
||||
|
||||
using SectionBuilder = void(*)(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void(Type)> showOther,
|
||||
rpl::producer<> showFinished);
|
||||
|
||||
class AbstractSection : public Ui::RpWidget {
|
||||
public:
|
||||
using RpWidget::RpWidget;
|
||||
|
||||
[[nodiscard]] virtual Type id() const = 0;
|
||||
[[nodiscard]] virtual rpl::producer<Type> sectionShowOther() {
|
||||
return nullptr;
|
||||
return _showOtherRequests.events();
|
||||
}
|
||||
[[nodiscard]] virtual rpl::producer<> sectionShowBack() {
|
||||
return nullptr;
|
||||
@@ -113,6 +119,7 @@ public:
|
||||
done();
|
||||
}
|
||||
virtual void showFinished() {
|
||||
_showFinished.fire({});
|
||||
}
|
||||
virtual void setInnerFocus() {
|
||||
setFocus();
|
||||
@@ -150,6 +157,33 @@ public:
|
||||
QRect clip) {
|
||||
return false;
|
||||
}
|
||||
|
||||
void showOther(Type type) {
|
||||
_showOtherRequests.fire_copy(type);
|
||||
}
|
||||
[[nodiscard]] Fn<void(Type)> showOtherMethod() {
|
||||
return crl::guard(this, [=](Type type) {
|
||||
showOther(type);
|
||||
});
|
||||
}
|
||||
|
||||
protected:
|
||||
void setController(not_null<Window::SessionController*> controller) {
|
||||
_controller = controller;
|
||||
}
|
||||
[[nodiscard]] Window::SessionController *controller() const {
|
||||
return _controller;
|
||||
}
|
||||
|
||||
void build(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
SectionBuilder builder);
|
||||
|
||||
private:
|
||||
rpl::event_stream<Type> _showOtherRequests;
|
||||
rpl::event_stream<> _showFinished;
|
||||
Window::SessionController *_controller = nullptr;
|
||||
|
||||
};
|
||||
|
||||
enum class IconType {
|
||||
|
||||
@@ -65,12 +65,6 @@ struct SectionFactory : AbstractSectionFactory {
|
||||
|
||||
};
|
||||
|
||||
using SectionBuilder = void(*)(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
not_null<Window::SessionController*> controller,
|
||||
Fn<void(Type)> showOther,
|
||||
rpl::producer<> showFinished);
|
||||
|
||||
template <typename SectionType>
|
||||
class Section : public AbstractSection {
|
||||
public:
|
||||
@@ -83,45 +77,6 @@ public:
|
||||
return Id();
|
||||
}
|
||||
|
||||
[[nodiscard]] rpl::producer<Type> sectionShowOther() final override {
|
||||
return _showOtherRequests.events();
|
||||
}
|
||||
void showOther(Type type) {
|
||||
_showOtherRequests.fire_copy(type);
|
||||
}
|
||||
[[nodiscard]] Fn<void(Type)> showOtherMethod() {
|
||||
return crl::guard(this, [=](Type type) {
|
||||
showOther(type);
|
||||
});
|
||||
}
|
||||
|
||||
void showFinished() override {
|
||||
_showFinished.fire({});
|
||||
}
|
||||
|
||||
protected:
|
||||
void setController(not_null<Window::SessionController*> controller) {
|
||||
_controller = controller;
|
||||
}
|
||||
[[nodiscard]] Window::SessionController *controller() const {
|
||||
return _controller;
|
||||
}
|
||||
|
||||
void build(
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
SectionBuilder builder) {
|
||||
builder(
|
||||
container,
|
||||
_controller,
|
||||
showOtherMethod(),
|
||||
_showFinished.events());
|
||||
}
|
||||
|
||||
private:
|
||||
rpl::event_stream<Type> _showOtherRequests;
|
||||
rpl::event_stream<> _showFinished;
|
||||
Window::SessionController *_controller = nullptr;
|
||||
|
||||
};
|
||||
|
||||
bool HasMenu(Type type);
|
||||
|
||||
@@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "settings/settings_privacy_security.h"
|
||||
|
||||
#include "settings/builder/settings_privacy_security_builder.h"
|
||||
#include "api/api_authorizations.h"
|
||||
#include "api/api_cloud_password.h"
|
||||
#include "api/api_self_destruct.h"
|
||||
@@ -274,6 +275,52 @@ rpl::producer<int> BlockedPeersCount(not_null<::Main::Session*> session) {
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void AddPrivacyPremiumStar(
|
||||
not_null<Ui::SettingsButton*> button,
|
||||
not_null<Main::Session*> session,
|
||||
rpl::producer<QString> label,
|
||||
const QMargins &padding) {
|
||||
const auto badge = Ui::CreateChild<Ui::RpWidget>(button.get());
|
||||
badge->showOn(Data::AmPremiumValue(session));
|
||||
const auto sampleLeft = st::settingsColorSamplePadding.left();
|
||||
const auto badgeLeft = padding.left() + sampleLeft;
|
||||
|
||||
const auto factor = style::DevicePixelRatio();
|
||||
const auto size = Size(st::settingsButtonNoIcon.style.font->ascent);
|
||||
auto starImage = QImage(
|
||||
size * factor,
|
||||
QImage::Format_ARGB32_Premultiplied);
|
||||
starImage.setDevicePixelRatio(factor);
|
||||
starImage.fill(Qt::transparent);
|
||||
{
|
||||
auto p = QPainter(&starImage);
|
||||
auto star = QSvgRenderer(
|
||||
Ui::Premium::ColorizedSvg(Ui::Premium::ButtonGradientStops()));
|
||||
star.render(&p, Rect(size));
|
||||
}
|
||||
|
||||
badge->resize(starImage.size() / style::DevicePixelRatio());
|
||||
badge->paintRequest(
|
||||
) | rpl::on_next([=, star = std::move(starImage)] {
|
||||
auto p = QPainter(badge);
|
||||
p.drawImage(0, 0, star);
|
||||
}, badge->lifetime());
|
||||
|
||||
rpl::combine(
|
||||
button->sizeValue(),
|
||||
std::move(label)
|
||||
) | rpl::on_next([=](const QSize &s, const QString &) {
|
||||
if (s.isNull()) {
|
||||
return;
|
||||
}
|
||||
badge->moveToLeft(
|
||||
button->fullTextWidth() + badgeLeft,
|
||||
(s.height() - badge->height()) / 2);
|
||||
}, badge->lifetime());
|
||||
}
|
||||
|
||||
void SetupPrivacy(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
@@ -894,8 +941,6 @@ void SetupSecurity(
|
||||
showOther);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void SetupSensitiveContent(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
@@ -1128,19 +1173,8 @@ void PrivacySecurity::setupContent(
|
||||
not_null<Window::SessionController*> controller) {
|
||||
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
||||
|
||||
auto updateOnTick = rpl::single(
|
||||
) | rpl::then(base::timer_each(kUpdateTimeout));
|
||||
const auto trigger = [=] {
|
||||
return rpl::duplicate(updateOnTick);
|
||||
};
|
||||
|
||||
SetupSecurity(controller, content, trigger(), showOtherMethod());
|
||||
SetupPrivacy(controller, content, trigger());
|
||||
SetupArchiveAndMute(controller, content);
|
||||
SetupBotsAndWebsites(controller, content);
|
||||
SetupConfirmationExtensions(controller, content);
|
||||
SetupTopPeers(controller, content);
|
||||
SetupSelfDestruction(controller, content, trigger());
|
||||
setController(controller);
|
||||
build(content, Builder::PrivacySecuritySection);
|
||||
|
||||
Ui::ResizeFitChild(this, content);
|
||||
}
|
||||
|
||||
@@ -40,10 +40,44 @@ not_null<Ui::SettingsButton*> AddPrivacyButton(
|
||||
Fn<std::unique_ptr<EditPrivacyController>()> controllerFactory,
|
||||
const style::SettingsButton *stOverride = nullptr);
|
||||
|
||||
void AddPrivacyPremiumStar(
|
||||
not_null<Ui::SettingsButton*> button,
|
||||
not_null<::Main::Session*> session,
|
||||
rpl::producer<QString> label,
|
||||
const QMargins &padding);
|
||||
|
||||
void SetupArchiveAndMute(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
void SetupSecurity(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<> updateTrigger,
|
||||
Fn<void(Type)> showOther);
|
||||
|
||||
void SetupPrivacy(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<> updateTrigger);
|
||||
|
||||
void SetupBotsAndWebsites(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
void SetupConfirmationExtensions(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
void SetupTopPeers(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container);
|
||||
|
||||
void SetupSelfDestruction(
|
||||
not_null<Window::SessionController*> controller,
|
||||
not_null<Ui::VerticalLayout*> container,
|
||||
rpl::producer<> updateTrigger);
|
||||
|
||||
class PrivacySecurity : public Section<PrivacySecurity> {
|
||||
public:
|
||||
PrivacySecurity(
|
||||
|
||||
Reference in New Issue
Block a user