From b0ddca72ae52d9eff3907f672d653ca0745d93d1 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 14 Jan 2026 18:25:46 +0400 Subject: [PATCH] Upgrade settings_blocked_peers to full builder pattern Move Blocked class to anonymous namespace in .cpp, export only Type BlockedPeersId() in header. Remove extern SectionBuildMethod from header. Update references in privacy_security and deep_links. Co-Authored-By: Claude Opus 4.5 --- .../core/deep_links/deep_links_settings.cpp | 4 +- .../sections/settings_blocked_peers.cpp | 89 ++++++++++++++++--- .../sections/settings_blocked_peers.h | 44 +-------- .../sections/settings_privacy_security.cpp | 4 +- 4 files changed, 82 insertions(+), 59 deletions(-) diff --git a/Telegram/SourceFiles/core/deep_links/deep_links_settings.cpp b/Telegram/SourceFiles/core/deep_links/deep_links_settings.cpp index 497cf3751b..0833327648 100644 --- a/Telegram/SourceFiles/core/deep_links/deep_links_settings.cpp +++ b/Telegram/SourceFiles/core/deep_links/deep_links_settings.cpp @@ -493,13 +493,13 @@ void RegisterSettingsHandlers(Router &router) { router.add(u"settings"_q, { .path = u"privacy/blocked"_q, - .action = SettingsSection{ ::Settings::Blocked::Id() }, + .action = SettingsSection{ ::Settings::BlockedPeersId() }, }); router.add(u"settings"_q, { .path = u"privacy/blocked/block-user"_q, .action = SettingsControl{ - ::Settings::Blocked::Id(), + ::Settings::BlockedPeersId(), u"privacy/blocked/block-user"_q, }, }); diff --git a/Telegram/SourceFiles/settings/sections/settings_blocked_peers.cpp b/Telegram/SourceFiles/settings/sections/settings_blocked_peers.cpp index 86fd860500..f787bc473e 100644 --- a/Telegram/SourceFiles/settings/sections/settings_blocked_peers.cpp +++ b/Telegram/SourceFiles/settings/sections/settings_blocked_peers.cpp @@ -51,16 +51,37 @@ void BuildBlockedSection(SectionBuilder &builder) { }); } -const auto kMeta = BuildHelper({ - .id = Blocked::Id(), - .parentId = PrivacySecurity::Id(), - .title = &tr::lng_settings_blocked_users, - .icon = &st::menuIconBlock, -}, [](SectionBuilder &builder) { - BuildBlockedSection(builder); -}); +class Blocked : public Section { +public: + Blocked( + QWidget *parent, + not_null controller); -} // namespace + void showFinished() override; + + [[nodiscard]] rpl::producer title() override; + + [[nodiscard]] base::weak_qptr createPinnedToTop( + not_null parent) override; + +private: + void setupContent(); + void checkTotal(int total); + + void visibleTopBottomUpdated(int visibleTop, int visibleBottom) override; + + const not_null _container; + + base::unique_qptr _loading; + + rpl::variable _countBlocked; + + rpl::event_stream<> _showFinished; + rpl::event_stream _emptinessChanges; + + QPointer _blockUserButton; + +}; Blocked::Blocked( QWidget *parent, @@ -255,7 +276,39 @@ void Blocked::setupContent() { resize(width(), std::max(height, min)); }, _container->lifetime()); - build(_container, Builder::BlockedSection); + const SectionBuildMethod buildMethod = []( + not_null container, + not_null controller, + Fn showOther, + rpl::producer<> showFinished) { + auto &lifetime = container->lifetime(); + const auto highlights = lifetime.make_state(); + + auto builder = SectionBuilder(WidgetContext{ + .container = container, + .controller = controller, + .showOther = std::move(showOther), + .isPaused = Window::PausedIn( + controller, + Window::GifPauseReason::Layer), + .highlights = highlights, + }); + + BuildBlockedSection(builder); + + 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); + }; + + build(_container, buildMethod); } void Blocked::checkTotal(int total) { @@ -275,9 +328,19 @@ void Blocked::showFinished() { _blockUserButton); } -namespace Builder { +const auto kMeta = BuildHelper({ + .id = Blocked::Id(), + .parentId = PrivacySecurity::Id(), + .title = &tr::lng_settings_blocked_users, + .icon = &st::menuIconBlock, +}, [](SectionBuilder &builder) { + BuildBlockedSection(builder); +}); -SectionBuildMethod BlockedSection = kMeta.build; +} // namespace + +Type BlockedPeersId() { + return Blocked::Id(); +} -} // namespace Builder } // namespace Settings diff --git a/Telegram/SourceFiles/settings/sections/settings_blocked_peers.h b/Telegram/SourceFiles/settings/sections/settings_blocked_peers.h index 0586aff5f7..d520ced168 100644 --- a/Telegram/SourceFiles/settings/sections/settings_blocked_peers.h +++ b/Telegram/SourceFiles/settings/sections/settings_blocked_peers.h @@ -7,54 +7,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "settings/settings_common_session.h" #include "settings/settings_type.h" -namespace Ui { -class VerticalLayout; -} // namespace Ui - namespace Window { -class Controller; +class SessionController; } // namespace Window namespace Settings { -class Blocked : public Section { -public: - Blocked( - QWidget *parent, - not_null controller); +[[nodiscard]] Type BlockedPeersId(); - void showFinished() override; - - [[nodiscard]] rpl::producer title() override; - - [[nodiscard]] base::weak_qptr createPinnedToTop( - not_null parent) override; - -private: - void setupContent(); - void checkTotal(int total); - - void visibleTopBottomUpdated(int visibleTop, int visibleBottom) override; - - const not_null _container; - - base::unique_qptr _loading; - - rpl::variable _countBlocked; - - rpl::event_stream<> _showFinished; - rpl::event_stream _emptinessChanges; - - QPointer _blockUserButton; - -}; - -namespace Builder { - -extern SectionBuildMethod BlockedSection; - -} // namespace Builder } // namespace Settings diff --git a/Telegram/SourceFiles/settings/sections/settings_privacy_security.cpp b/Telegram/SourceFiles/settings/sections/settings_privacy_security.cpp index e221d86179..f3d391314b 100644 --- a/Telegram/SourceFiles/settings/sections/settings_privacy_security.cpp +++ b/Telegram/SourceFiles/settings/sections/settings_privacy_security.cpp @@ -516,7 +516,7 @@ void SetupBlockedList( st::settingsButton, { &st::menuIconBlock }); blockedPeers->addClickHandler([=] { - showOther(Blocked::Id()); + showOther(BlockedPeersId()); }); std::move( updateTrigger @@ -1370,7 +1370,7 @@ void BuildSecuritySection( .icon = { &st::menuIconBlock }, .label = std::move(blockedCount), .onClick = [=] { - showOther(Blocked::Id()); + showOther(BlockedPeersId()); }, .keywords = { u"blocked"_q, u"ban"_q }, });