user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 2/2] nntp: add "newsgroup" parameter and sort grouplist
Date: Sun, 20 Sep 2015 10:28:48 +0000	[thread overview]
Message-ID: <20150920102848.21570-3-e@80x24.org> (raw)
In-Reply-To: <20150920102848.21570-1-e@80x24.org>

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.
---
 lib/PublicInbox/NNTP.pm | 12 ++++++------
 public-inbox-nntpd      | 26 +++++++++++++++++++-------
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 8f86685..79f2c2f 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -93,7 +93,7 @@ sub list_overview_fmt ($$) {
 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);
 	}
@@ -102,7 +102,7 @@ sub list_active ($;$) {
 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}");
@@ -112,7 +112,7 @@ sub list_active_times ($;$) {
 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");
@@ -137,7 +137,7 @@ sub cmd_list ($;$$) {
 		$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);
 		}
 	}
@@ -200,7 +200,7 @@ sub cmd_newgroups ($$$;$$) {
 
 	# 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);
@@ -249,7 +249,7 @@ sub cmd_newnews ($$$$;$$) {
 	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;
diff --git a/public-inbox-nntpd b/public-inbox-nntpd
index b66de58..0395e98 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;
-- 
EW


      parent reply	other threads:[~2015-09-20 10:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-20 10:28 [PATCH 0/2] nntp: newsgroup names now supported Eric Wong
2015-09-20 10:28 ` [PATCH 1/2] newsgroup: use only the first address Eric Wong
2015-09-20 10:28 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150920102848.21570-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).