From: Eric Wong Date: Thu, 27 Mar 2025 23:20:43 +0000 (+0000) Subject: nntp: share common LIST code to reduce duplication X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d5b786b9af70a3094f2e2ce3a1be1482920b3be6;p=thirdparty%2Fpublic-inbox.git nntp: share common LIST code to reduce duplication Deduplicating code here will make a future change to wildmat2re easier-to-review. --- 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