From d5b786b9af70a3094f2e2ce3a1be1482920b3be6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 27 Mar 2025 23:20:43 +0000 Subject: [PATCH] nntp: share common LIST code to reduce duplication Deduplicating code here will make a future change to wildmat2re easier-to-review. --- lib/PublicInbox/NNTP.pm | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm index 6fa9159fe..cdfbd35c7 100644 --- a/lib/PublicInbox/NNTP.pm +++ b/lib/PublicInbox/NNTP.pm @@ -119,6 +119,13 @@ sub names2ibx ($;$) { } } +sub _list_groups (@) { + my ($cb, $self, $wildmat) = @_; + wildmat2re($wildmat); + my @names = grep /$wildmat/, @{$self->{nntpd}->{groupnames}}; + $self->long_response($cb, names2ibx($self, \@names)); +} + sub list_active_i { # "LIST ACTIVE" and also just "LIST" (no args) my ($self, $ibxs) = @_; my @window = splice(@$ibxs, 0, 1000); @@ -127,10 +134,7 @@ sub list_active_i { # "LIST ACTIVE" and also just "LIST" (no args) } sub list_active ($;$) { # called by cmd_list - my ($self, $wildmat) = @_; - wildmat2re($wildmat); - my @names = grep(/$wildmat/, @{$self->{nntpd}->{groupnames}}); - $self->long_response(\&list_active_i, names2ibx($self, \@names)); + _list_groups \&list_active_i, @_; } sub list_active_times_i { @@ -144,10 +148,7 @@ sub list_active_times_i { } sub list_active_times ($;$) { # called by cmd_list - my ($self, $wildmat) = @_; - wildmat2re($wildmat); - my @names = grep(/$wildmat/, @{$self->{nntpd}->{groupnames}}); - $self->long_response(\&list_active_times_i, names2ibx($self, \@names)); + _list_groups \&list_active_times_i, @_; } sub list_newsgroups_i { @@ -160,10 +161,7 @@ sub list_newsgroups_i { } sub list_newsgroups ($;$) { # called by cmd_list - my ($self, $wildmat) = @_; - wildmat2re($wildmat); - my @names = grep(/$wildmat/, @{$self->{nntpd}->{groupnames}}); - $self->long_response(\&list_newsgroups_i, names2ibx($self, \@names)); + _list_groups \&list_newsgroups_i, @_; } # LIST SUBSCRIPTIONS, DISTRIB.PATS are not supported -- 2.47.3