1 # Copyright (C) 2015 all contributors <meta@public-inbox.org>
2 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
4 # Used only by the NNTP server to represent a public-inbox git repository
6 package PublicInbox::NewsGroup;
9 use Scalar::Util qw(weaken);
10 require Danga::Socket;
11 require PublicInbox::Msgmap;
12 require PublicInbox::Search;
13 require PublicInbox::Git;
16 my ($class, $newsgroup, $git_dir, $address, $url) = @_;
18 # first email address is preferred
19 $address = $address->[0] if ref($address);
21 # assume protocol-relative URLs which start with '//' means
22 # the server supports both HTTP and HTTPS, favor HTTPS.
23 $url = "https:$url" if $url =~ m!\A//!;
24 $url .= '/' if $url !~ m!/\z!;
27 newsgroup => $newsgroup,
32 $self->{domain} = ($address =~ /\@(\S+)\z/) ? $1 : 'localhost';
38 weaken($self->{$_}) foreach qw(gcf mm search);
43 $self->{gcf} ||= eval { PublicInbox::Git->new($self->{git_dir}) };
49 PublicInbox::Msgmap->new($self->{git_dir});
50 PublicInbox::Search->new($self->{git_dir});
56 $self->{mm} ||= eval { PublicInbox::Msgmap->new($self->{git_dir}) };
61 $self->{search} ||= eval { PublicInbox::Search->new($self->{git_dir}) };
66 open my $fh, '<', "$self->{git_dir}/description" or return '';
67 my $desc = eval { local $/; <$fh> };
74 my ($self, $new) = @_;
75 $self->{address} = $new->{address};
76 $self->{domain} = $new->{domain};
77 if ($self->{git_dir} ne $new->{git_dir}) {
78 # new git_dir requires a new mm and gcf
79 $self->{mm} = $self->{gcf} = undef;
80 $self->{git_dir} = $new->{git_dir};