about summary refs log tree commit homepage
path: root/public-inbox-nntpd
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-09-20 09:34:52 +0000
committerEric Wong <e@80x24.org>2015-09-20 09:34:52 +0000
commitcb2d1876d776ae6b8ec1d172f1f64169fe1efd5c (patch)
treef42668ab116d78e74ba278c84de7cd278665aeb5 /public-inbox-nntpd
parent2409d31225754eb27f2bea9cc4dc91d73f48fbc8 (diff)
downloadpublic-inbox-cb2d1876d776ae6b8ec1d172f1f64169fe1efd5c.tar.gz
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.
Diffstat (limited to 'public-inbox-nntpd')
-rw-r--r--public-inbox-nntpd26
1 files changed, 19 insertions, 7 deletions
diff --git a/public-inbox-nntpd b/public-inbox-nntpd
index b66de58e..0395e98b 100644
--- a/public-inbox-nntpd
+++ b/public-inbox-nntpd
@@ -298,7 +298,7 @@ sub event_read {
 package PublicInbox::NNTPD;
 use strict;
 use warnings;
-use fields qw(groups err out);
+use fields qw(groups grouplist err out);
 
 sub new {
         my ($class) = @_;
@@ -306,6 +306,7 @@ sub new {
         $self->{groups} = {};
         $self->{err} = \*STDERR;
         $self->{out} = \*STDOUT;
+        $self->{grouplist} = [];
         $self;
 }
 
@@ -314,26 +315,37 @@ sub refresh_groups {
         require PublicInbox::Config;
         my $pi_config = PublicInbox::Config->new;
         my $new = {};
+        my @list;
         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};
 
-                # 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
-                $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;
-};
+}
 
 1;