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 <noreply@anthropic.com>
This commit is contained in:
John Preston
2026-01-14 18:25:46 +04:00
parent 7dbeb56111
commit b0ddca72ae
4 changed files with 82 additions and 59 deletions
@@ -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<Blocked> {
public:
Blocked(
QWidget *parent,
not_null<Window::SessionController*> controller);
} // namespace
void showFinished() override;
[[nodiscard]] rpl::producer<QString> title() override;
[[nodiscard]] base::weak_qptr<Ui::RpWidget> createPinnedToTop(
not_null<QWidget*> parent) override;
private:
void setupContent();
void checkTotal(int total);
void visibleTopBottomUpdated(int visibleTop, int visibleBottom) override;
const not_null<Ui::VerticalLayout*> _container;
base::unique_qptr<Ui::RpWidget> _loading;
rpl::variable<int> _countBlocked;
rpl::event_stream<> _showFinished;
rpl::event_stream<bool> _emptinessChanges;
QPointer<Ui::RpWidget> _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<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>();
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
@@ -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<Blocked> {
public:
Blocked(
QWidget *parent,
not_null<Window::SessionController*> controller);
[[nodiscard]] Type BlockedPeersId();
void showFinished() override;
[[nodiscard]] rpl::producer<QString> title() override;
[[nodiscard]] base::weak_qptr<Ui::RpWidget> createPinnedToTop(
not_null<QWidget*> parent) override;
private:
void setupContent();
void checkTotal(int total);
void visibleTopBottomUpdated(int visibleTop, int visibleBottom) override;
const not_null<Ui::VerticalLayout*> _container;
base::unique_qptr<Ui::RpWidget> _loading;
rpl::variable<int> _countBlocked;
rpl::event_stream<> _showFinished;
rpl::event_stream<bool> _emptinessChanges;
QPointer<Ui::RpWidget> _blockUserButton;
};
namespace Builder {
extern SectionBuildMethod BlockedSection;
} // namespace Builder
} // namespace Settings
@@ -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 },
});