From d966dc2343806f34aa6b623d64c192fc08fda6fd Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 14 Jan 2026 17:18:27 +0400 Subject: [PATCH] Rewrite settings_notifications_type to new builder pattern Co-Authored-By: Claude Opus 4.5 --- Telegram/CMakeLists.txt | 4 +- .../core/deep_links/deep_links_settings.cpp | 2 +- .../sections/settings_notifications.cpp | 2 +- .../settings_notifications_type.cpp | 70 ++++++++++++++----- .../settings_notifications_type.h | 0 5 files changed, 57 insertions(+), 21 deletions(-) rename Telegram/SourceFiles/settings/{ => sections}/settings_notifications_type.cpp (92%) rename Telegram/SourceFiles/settings/{ => sections}/settings_notifications_type.h (100%) diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 6fad827e0c..85b9799f76 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -1586,8 +1586,8 @@ PRIVATE settings/sections/settings_notifications.h settings/sections/settings_privacy_security.cpp settings/sections/settings_privacy_security.h - settings/settings_notifications_type.cpp - settings/settings_notifications_type.h + settings/sections/settings_notifications_type.cpp + settings/sections/settings_notifications_type.h settings/settings_passkeys.cpp settings/settings_passkeys.h settings/settings_power_saving.cpp diff --git a/Telegram/SourceFiles/core/deep_links/deep_links_settings.cpp b/Telegram/SourceFiles/core/deep_links/deep_links_settings.cpp index b551d419a4..ac573dc69b 100644 --- a/Telegram/SourceFiles/core/deep_links/deep_links_settings.cpp +++ b/Telegram/SourceFiles/core/deep_links/deep_links_settings.cpp @@ -59,7 +59,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_cloud_password.h" #include "core/core_cloud_password.h" #include "settings/sections/settings_notifications.h" -#include "settings/settings_notifications_type.h" +#include "settings/sections/settings_notifications_type.h" #include "settings/settings_power_saving.h" #include "settings/settings_premium.h" #include "ui/power_saving.h" diff --git a/Telegram/SourceFiles/settings/sections/settings_notifications.cpp b/Telegram/SourceFiles/settings/sections/settings_notifications.cpp index 95a53dce15..a66a4f37ef 100644 --- a/Telegram/SourceFiles/settings/sections/settings_notifications.cpp +++ b/Telegram/SourceFiles/settings/sections/settings_notifications.cpp @@ -27,7 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "settings/settings_builder.h" #include "settings/sections/settings_main.h" #include "settings/settings_notifications_common.h" -#include "settings/settings_notifications_type.h" +#include "settings/sections/settings_notifications_type.h" #include "ui/boxes/confirm_box.h" #include "ui/chat/chat_theme.h" #include "ui/controls/chat_service_checkbox.h" diff --git a/Telegram/SourceFiles/settings/settings_notifications_type.cpp b/Telegram/SourceFiles/settings/sections/settings_notifications_type.cpp similarity index 92% rename from Telegram/SourceFiles/settings/settings_notifications_type.cpp rename to Telegram/SourceFiles/settings/sections/settings_notifications_type.cpp index a144fd03b4..11c1856a0a 100644 --- a/Telegram/SourceFiles/settings/settings_notifications_type.cpp +++ b/Telegram/SourceFiles/settings/sections/settings_notifications_type.cpp @@ -5,7 +5,7 @@ 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_notifications_type.h" +#include "settings/sections/settings_notifications_type.h" #include "api/api_ringtones.h" #include "apiwrap.h" @@ -24,6 +24,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "menu/menu_mute.h" #include "platform/platform_notifications_manager.h" +#include "settings/sections/settings_notifications.h" +#include "settings/settings_builder.h" +#include "settings/settings_common.h" #include "ui/boxes/confirm_box.h" #include "ui/widgets/buttons.h" #include "ui/widgets/popup_menu.h" @@ -31,7 +34,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/wrap/vertical_layout.h" #include "ui/vertical_list.h" #include "window/window_session_controller.h" -#include "settings/settings_common.h" #include "styles/style_layers.h" #include "styles/style_menu_icons.h" #include "styles/style_settings.h" @@ -40,6 +42,7 @@ namespace Settings { namespace { using Notify = Data::DefaultNotify; +using namespace Builder; struct NotificationsTypeHighlightTargets { QPointer showToggle; @@ -69,11 +72,11 @@ class AddExceptionBoxController final , public base::has_weak_ptr { public: AddExceptionBoxController( - not_null session, + not_null<::Main::Session*> session, Notify type, Fn)> done); - Main::Session &session() const override; + ::Main::Session &session() const override; void rowClicked(not_null row) override; base::unique_qptr rowContextMenu( QWidget *parent, @@ -83,7 +86,7 @@ private: void prepareViewHook() override; std::unique_ptr createRow(not_null history) override; - const not_null _session; + const not_null<::Main::Session*> _session; const Notify _type; const Fn)> _done; @@ -100,7 +103,7 @@ public: not_null window, Notify type); - Main::Session &session() const override; + ::Main::Session &session() const override; void prepare() override; void rowClicked(not_null row) override; base::unique_qptr rowContextMenu( @@ -136,7 +139,7 @@ private: }; AddExceptionBoxController::AddExceptionBoxController( - not_null session, + not_null<::Main::Session*> session, Notify type, Fn)> done) : ChatsListBoxController(session) @@ -145,7 +148,7 @@ AddExceptionBoxController::AddExceptionBoxController( , _done(std::move(done)) { } -Main::Session &AddExceptionBoxController::session() const { +::Main::Session &AddExceptionBoxController::session() const { return *_session; } @@ -180,11 +183,8 @@ base::unique_qptr AddExceptionBoxController::rowContextMenu( peer->owner().history(peer), delegate()->peerListUiShow()); - // First clear _menu value, so that we don't check row positions yet. base::take(_menu); - // Here unique_qptr is used like a shared pointer, where - // not the last destroyed pointer destroys the object, but the first. _menu = base::unique_qptr(result.get()); _menu->setDestroyedCallback(crl::guard(this, [=] { _lastClickedPeer = nullptr; @@ -213,7 +213,7 @@ ExceptionsController::ExceptionsController( , _type(type) { } -Main::Session &ExceptionsController::session() const { +::Main::Session &ExceptionsController::session() const { return _window->session(); } @@ -321,11 +321,8 @@ base::unique_qptr ExceptionsController::rowContextMenu( peer->owner().history(peer), _window->uiShow()); - // First clear _menu value, so that we don't check row positions yet. base::take(_menu); - // Here unique_qptr is used like a shared pointer, where - // not the last destroyed pointer destroys the object, but the first. _menu = base::unique_qptr(result.get()); return result; @@ -628,6 +625,45 @@ void SetupExceptions( anim::type::instant); } +const auto kMeta = BuildHelper({ + .id = NotificationsType::Id(Notify::User), + .parentId = Notifications::Id(), + .title = &tr::lng_notification_private_chats, + .icon = &st::menuIconProfile, +}, [](SectionBuilder &builder) { + builder.add(nullptr, [] { + return SearchEntry{ + .id = u"notifications/type/show"_q, + .title = tr::lng_notification_enable(tr::now), + .keywords = { u"enable"_q, u"notifications"_q, u"mute"_q }, + }; + }); + + builder.add(nullptr, [] { + return SearchEntry{ + .id = u"notifications/type/sound"_q, + .title = tr::lng_notification_sound(tr::now), + .keywords = { u"sound"_q, u"audio"_q, u"tone"_q }, + }; + }); + + builder.add(nullptr, [] { + return SearchEntry{ + .id = u"notifications/type/add-exception"_q, + .title = tr::lng_notification_exceptions_add(tr::now), + .keywords = { u"exception"_q, u"add"_q, u"exclude"_q }, + }; + }); + + builder.add(nullptr, [] { + return SearchEntry{ + .id = u"notifications/type/delete-exceptions"_q, + .title = tr::lng_notification_exceptions_clear(tr::now), + .keywords = { u"clear"_q, u"delete"_q, u"exceptions"_q }, + }; + }); +}); + } // namespace NotificationsType::NotificationsType( @@ -691,7 +727,7 @@ void NotificationsType::setupContent( } bool NotificationsEnabledForType( - not_null session, + not_null<::Main::Session*> session, Notify type) { const auto settings = &session->data().notifySettings(); const auto until = settings->defaultSettings(type).muteUntil(); @@ -699,7 +735,7 @@ bool NotificationsEnabledForType( } rpl::producer NotificationsEnabledForTypeValue( - not_null session, + not_null<::Main::Session*> session, Notify type) { const auto settings = &session->data().notifySettings(); return rpl::single( diff --git a/Telegram/SourceFiles/settings/settings_notifications_type.h b/Telegram/SourceFiles/settings/sections/settings_notifications_type.h similarity index 100% rename from Telegram/SourceFiles/settings/settings_notifications_type.h rename to Telegram/SourceFiles/settings/sections/settings_notifications_type.h