]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
searchview: save a column in &x=t thread skeleton
[public-inbox.git] / lib / PublicInbox / View.pm
index 00bf38a9590bee6cb3cd57bb69d06b901eeedb65..0b1026387f18c815f6bec6200fdc9f353e1f3922 100644 (file)
@@ -10,7 +10,7 @@ use bytes (); # only for bytes::length
 use PublicInbox::MsgTime qw(msg_datestamp);
 use PublicInbox::Hval qw/ascii_html obfuscate_addrs/;
 use PublicInbox::Linkify;
-use PublicInbox::MID qw/id_compress mid_escape mids references/;
+use PublicInbox::MID qw/id_compress mid_escape mids mids_for_index references/;
 use PublicInbox::MsgIter;
 use PublicInbox::Address;
 use PublicInbox::WwwStream;
@@ -629,7 +629,7 @@ sub _msg_html_prepare {
        my $over = $ctx->{-inbox}->over;
        my $obfs_ibx = $ctx->{-obfs_ibx};
        my $rv = '';
-       my $mids = mids($hdr);
+       my $mids = mids_for_index($hdr);
        if ($nr == 0) {
                if ($more) {
                        $rv .=
@@ -691,9 +691,13 @@ sub _msg_html_prepare {
                $rv .= "Message-ID: <$mhtml> ";
                $rv .= "(<a\nhref=\"raw\">raw</a>)\n";
        } else {
+               # X-Alt-Message-ID can happen if a message is injected from
+               # public-inbox-nntpd because of multiple Message-ID headers.
                my $lnk = PublicInbox::Linkify->new;
                my $s = '';
-               $s .= "Message-ID: $_\n" for ($hdr->header_raw('Message-ID'));
+               for my $h (qw(Message-ID X-Alt-Message-ID)) {
+                       $s .= "$h: $_\n" for ($hdr->header_raw($h));
+               }
                $lnk->linkify_mids('..', \$s, 1);
                $rv .= $s;
        }
@@ -877,8 +881,7 @@ sub strict_loose_note ($) {
 sub thread_results {
        my ($ctx, $msgs) = @_;
        require PublicInbox::SearchThread;
-       my $ibx = $ctx->{-inbox};
-       my $rootset = PublicInbox::SearchThread::thread($msgs, *sort_ds, $ibx);
+       my $rootset = PublicInbox::SearchThread::thread($msgs, \&sort_ds, $ctx);
 
        # FIXME: `tid' is broken on --reindex, so that needs to be fixed
        # and preserved in the future.  This bug is hidden by `sid' matches
@@ -947,7 +950,18 @@ sub skel_dump {
        my $obfs_ibx = $ctx->{-obfs_ibx};
        obfuscate_addrs($obfs_ibx, $f) if $obfs_ibx;
 
-       my $d = fmt_ts($smsg->{ds}) . ' ' . indent_for($level) . th_pfx($level);
+       my $d = fmt_ts($smsg->{ds});
+       my $unmatched; # if lazy-loaded by SearchThread::Msg::visible()
+       if (my $pct = $ctx->{pct}) {
+               $pct = $pct->{$smsg->{mid}};
+               if (defined $pct) {
+                       $d .= (sprintf(' % 2u', $pct) . '%');
+               } else {
+                       $unmatched = 1;
+                       $d .= '    ';
+               }
+       }
+       $d .= ' ' . indent_for($level) . th_pfx($level);
        my $attr = $f;
        $ctx->{first_level} ||= $level;
 
@@ -973,7 +987,6 @@ sub skel_dump {
        # our Xapian which would've resulted in '' if it were
        # really missing (and Filter rejects empty subjects)
        my @subj = split(/ /, subject_normalized($smsg->subject));
-
        # remove common suffixes from the subject if it matches the previous,
        # so we do not show redundant text at the end.
        my $prev_subj = $ctx->{prev_subj} || [];
@@ -990,7 +1003,7 @@ sub skel_dump {
        }
        my $m;
        my $id = '';
-       my $mapping = $ctx->{mapping};
+       my $mapping = $unmatched ? undef : $ctx->{mapping};
        if ($mapping) {
                my $map = $mapping->{$mid};
                $id = id_compress($mid, 1);
@@ -1008,8 +1021,8 @@ sub _skel_ghost {
        my ($ctx, $level, $node) = @_;
 
        my $mid = $node->{id};
-       my $d = $ctx->{pct} ? '    [irrelevant] ' # search result
-                           : '     [not found] ';
+       my $d = '     [not found] ';
+       $d .= '    '  if exists $ctx->{pct};
        $d .= indent_for($level) . th_pfx($level);
        my $upfx = $ctx->{-upfx};
        my $m = PublicInbox::Hval->new_msgid($mid);