]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/NNTPD.pm
remove redundant NewsGroup class
[public-inbox.git] / lib / PublicInbox / NNTPD.pm
1 # Copyright (C) 2016 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # represents an NNTPD (currently a singleton),
5 # see script/public-inbox-nntpd for how it is used
6 package PublicInbox::NNTPD;
7 use strict;
8 use warnings;
9 require PublicInbox::Config;
10
11 sub new {
12         my ($class) = @_;
13         bless {
14                 groups => {},
15                 err => \*STDERR,
16                 out => \*STDOUT,
17                 grouplist => [],
18         }, $class;
19 }
20
21 sub refresh_groups () {
22         my ($self) = @_;
23         my $pi_config = PublicInbox::Config->new;
24         my $new = {};
25         my @list;
26         foreach my $k (keys %$pi_config) {
27                 $k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
28                 my $name = $1;
29                 my $git_dir = $pi_config->{$k};
30                 my $ngname = $pi_config->{"publicinbox.$name.newsgroup"};
31                 next unless defined $ngname;
32                 next if ($ngname eq ''); # disabled
33                 my $ng = $pi_config->lookup_newsgroup($ngname) or next;
34
35                 # Only valid if msgmap and search works
36                 if ($ng->nntp_usable) {
37                         $new->{$ngname} = $ng;
38                         push @list, $ng;
39                 }
40         }
41         @list = sort { $a->{newsgroup} cmp $b->{newsgroup} } @list;
42         $self->{grouplist} = \@list;
43         # this will destroy old groups that got deleted
44         %{$self->{groups}} = %$new;
45 }
46
47 1;