Using non-hierarchical mailing list names for newsgroups
might confuse traditional newsreader software and perhaps
some humans. Allow administrators to configure newsgroups
names and hierarchies to their liking.
Sorting the grouplist alphabetically should probably be
done anyways to improve usability for some clients which
won't sort themselves.
sub list_active ($;$) {
my ($self, $wildmat) = @_;
wildmat2re($wildmat);
sub list_active ($;$) {
my ($self, $wildmat) = @_;
wildmat2re($wildmat);
- foreach my $ng (values %{$self->{nntpd}->{groups}}) {
+ foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
$ng->{name} =~ $wildmat or next;
group_line($self, $ng);
}
$ng->{name} =~ $wildmat or next;
group_line($self, $ng);
}
sub list_active_times ($;$) {
my ($self, $wildmat) = @_;
wildmat2re($wildmat);
sub list_active_times ($;$) {
my ($self, $wildmat) = @_;
wildmat2re($wildmat);
- foreach my $ng (values %{$self->{nntpd}->{groups}}) {
+ foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
$ng->{name} =~ $wildmat or next;
my $c = eval { $ng->mm->created_at } || time;
more($self, "$ng->{name} $c $ng->{address}");
$ng->{name} =~ $wildmat or next;
my $c = eval { $ng->mm->created_at } || time;
more($self, "$ng->{name} $c $ng->{address}");
sub list_newsgroups ($;$) {
my ($self, $wildmat) = @_;
wildmat2re($wildmat);
sub list_newsgroups ($;$) {
my ($self, $wildmat) = @_;
wildmat2re($wildmat);
- foreach my $ng (values %{$self->{nntpd}->{groups}}) {
+ foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
$ng->{name} =~ $wildmat or next;
my $d = $ng->description;
more($self, "$ng->{name} $d");
$ng->{name} =~ $wildmat or next;
my $d = $ng->description;
more($self, "$ng->{name} $d");
$arg->($self, @args);
} else {
more($self, '215 list of newsgroups follows');
$arg->($self, @args);
} else {
more($self, '215 list of newsgroups follows');
- foreach my $ng (values %{$self->{nntpd}->{groups}}) {
+ foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
group_line($self, $ng);
}
}
group_line($self, $ng);
}
}
# TODO dists
more($self, '231 list of new newsgroups follows');
# TODO dists
more($self, '231 list of new newsgroups follows');
- foreach my $ng (values %{$self->{nntpd}->{groups}}) {
+ foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
my $c = eval { $ng->mm->created_at } || 0;
next unless $c > $ts;
group_line($self, $ng);
my $c = eval { $ng->mm->created_at } || 0;
next unless $c > $ts;
group_line($self, $ng);
ngpat2re($keep);
ngpat2re($skip);
my @srch;
ngpat2re($keep);
ngpat2re($skip);
my @srch;
- foreach my $ng (values %{$self->{nntpd}->{groups}}) {
+ foreach my $ng (@{$self->{nntpd}->{grouplist}}) {
$ng->{name} =~ $keep or next;
$ng->{name} =~ $skip and next;
my $srch = $ng->search or next;
$ng->{name} =~ $keep or next;
$ng->{name} =~ $skip and next;
my $srch = $ng->search or next;
package PublicInbox::NNTPD;
use strict;
use warnings;
package PublicInbox::NNTPD;
use strict;
use warnings;
-use fields qw(groups err out);
+use fields qw(groups grouplist err out);
sub new {
my ($class) = @_;
sub new {
my ($class) = @_;
$self->{groups} = {};
$self->{err} = \*STDERR;
$self->{out} = \*STDOUT;
$self->{groups} = {};
$self->{err} = \*STDERR;
$self->{out} = \*STDOUT;
+ $self->{grouplist} = [];
require PublicInbox::Config;
my $pi_config = PublicInbox::Config->new;
my $new = {};
require PublicInbox::Config;
my $pi_config = PublicInbox::Config->new;
my $new = {};
foreach my $k (keys %$pi_config) {
$k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
my $g = $1;
my $git_dir = $pi_config->{$k};
foreach my $k (keys %$pi_config) {
$k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
my $g = $1;
my $git_dir = $pi_config->{$k};
- my $address = $pi_config->{"publicinbox.$g.address"};
- my $ng = PublicInbox::NewsGroup->new($g, $git_dir, $address);
+ my $addr = $pi_config->{"publicinbox.$g.address"};
+ my $ngname = $pi_config->{"publicinbox.$g.newsgroup"};
+ if (defined $ngname) {
+ next if ($ngname eq ''); # disabled
+ $g = $ngname;
+ }
+ my $ng = PublicInbox::NewsGroup->new($g, $git_dir, $addr);
my $old_ng = $self->{groups}->{$g};
my $old_ng = $self->{groups}->{$g};
- # Reuse the old one if possible since it can hold references
- # to valid mm and gcf objects
+ # Reuse the old one if possible since it can hold
+ # references to valid mm and gcf objects
if ($old_ng) {
$old_ng->update($ng);
$ng = $old_ng;
}
# Only valid if Msgmap works
if ($old_ng) {
$old_ng->update($ng);
$ng = $old_ng;
}
# Only valid if Msgmap works
- $new->{$g} = $ng if $ng->mm(1);
+ if ($ng->mm(1)) {
+ $new->{$g} = $ng;
+ push @list, $ng;
+ }
+ @list = sort { $a->{name} cmp $b->{name} } @list;
+ $self->{grouplist} = \@list;
# this will destroy old groups that got deleted
%{$self->{groups}} = %$new;
# this will destroy old groups that got deleted
%{$self->{groups}} = %$new;