]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
view: reduce visual noise in conversation view
[public-inbox.git] / lib / PublicInbox / View.pm
index fd882aa031f3be3f4751c77bad077a75cfab788a..7be72cfc642d19995f6d78cd29ac57700b07bc7f 100644 (file)
@@ -24,14 +24,13 @@ sub th_pfx ($) { $_[0] == 0 ? '' : TCHILD };
 
 # public functions: (unstable)
 sub msg_html {
-       my ($ctx, $mime, $footer) = @_;
+       my ($ctx, $mime) = @_;
        my $hdr = $mime->header_obj;
        my $tip = _msg_html_prepare($hdr, $ctx);
        PublicInbox::WwwStream->response($ctx, 200, sub {
                my ($nr, undef) = @_;
                if ($nr == 1) {
-                       $tip . multipart_text_as_html($mime, '') .
-                               '</pre><hr />'
+                       $tip . multipart_text_as_html($mime, '') . '</pre><hr>'
                } elsif ($nr == 2) {
                        # fake an EOF if generating the footer fails;
                        # we want to at least show the message if something
@@ -157,10 +156,10 @@ sub index_entry {
        # add the footer
        $rv .= "\n<a\nhref=#$id_m\nid=e$id>^</a> ".
                "<a\nhref=\"$mhref\">permalink</a>" .
-               " <a\nhref=\"${mhref}raw\">raw</a>" .
-               " <a\nhref=\"${mhref}#R\">reply</a>";
+               " <a\nhref=\"${mhref}raw\">raw</a>" .
+               " <a\nhref=\"${mhref}#R\">reply</a>";
        if (my $pct = $ctx->{pct}) { # used by SearchView.pm
-               $rv .= " [relevance $pct->{$mid_raw}%]";
+               $rv .= "\t[relevance $pct->{$mid_raw}%]";
        } elsif ($mapping) {
                my $threaded = 'threaded';
                my $flat = 'flat';
@@ -170,9 +169,9 @@ sub index_entry {
                } else {
                        $threaded = "<b>$threaded</b>";
                }
-               $rv .= " / [<a\nhref=\"${mhref}T/#u\">$flat</a>";
+               $rv .= "\t[<a\nhref=\"${mhref}T/#u\">$flat</a>";
                $rv .= "|<a\nhref=\"${mhref}t/#u\">$threaded</a>]";
-               $rv .= " <a\nhref=#r$id>$ctx->{s_nr}</a>";
+               $rv .= " <a\nhref=#r$id>$ctx->{s_nr}</a>";
        }
 
        $rv .= $more ? "\n\n" : "\n";
@@ -219,6 +218,7 @@ sub _th_index_lite {
        my $this = $map->[1];
        $this =~ s!\n\z!</b>\n!s;
        $this =~ s!<a\nhref.*</a> !!s; # no point in duplicating subject
+       $this =~ s!<a\nhref=[^>]+>([^<]+)</a>!$1!s; # no point linking to self
        $rv .= "<b>@ $this";
        my $node = $map->[2];
        if (my $child = $node->child) {
@@ -320,7 +320,7 @@ sub thread_html {
        my $msgs = load_results($sres);
        my $nr = $sres->{total};
        return missing_thread($ctx) if $nr == 0;
-       my $skel = '<hr /><pre>';
+       my $skel = '<hr><pre>';
        $skel .= $nr == 1 ? 'only message in thread' : 'end of thread';
        $skel .= ", back to <a\nhref=\"../../\">index</a>";
        $skel .= "\n<a\nid=t>$nr+ messages in thread:</a> (download: ";
@@ -550,7 +550,7 @@ sub _parent_headers {
 
        my $irt = in_reply_to($hdr);
        if (defined $irt) {
-               my $v = PublicInbox::Hval->new_msgid($irt, 1);
+               my $v = PublicInbox::Hval->new_msgid($irt);
                my $html = $v->as_html;
                my $href = $v->as_href;
                $rv .= "In-Reply-To: &lt;";
@@ -660,7 +660,7 @@ sub html_footer {
 }
 
 sub linkify_ref_nosrch {
-       my $v = PublicInbox::Hval->new_msgid($_[0], 1);
+       my $v = PublicInbox::Hval->new_msgid($_[0]);
        my $html = $v->as_html;
        my $href = $v->as_href;
        "&lt;<a\nhref=\"../$href/\">$html</a>&gt;";
@@ -853,13 +853,15 @@ sub add_topic {
        }
 }
 
-sub emit_topics {
+sub topics {
        my ($ctx) = @_;
        my $order = $ctx->{order};
        my $subjs = $ctx->{subjs};
        my $latest = $ctx->{latest};
-       my $fh = $ctx->{fh};
-       return $fh->write("\n[No topics in range]</pre>") unless scalar @$order;
+       if (!@$order) {
+               $ctx->{-html_tip} = '<pre>[No topics in range]</pre>';
+               return 404;
+       }
        my $pfx;
        my $prev = 0;
        my $prev_attr = '';
@@ -869,7 +871,7 @@ sub emit_topics {
                my ($level, $subj) = @$info;
                my $n = delete $subjs->{$subj};
                my ($mid, $ts) = @{delete $latest->{$subj}};
-               $mid = PublicInbox::Hval->new_msgid($mid)->as_href;
+               my $href = PublicInbox::Hval->new_msgid($mid)->as_href;
                $pfx = indent_for($level);
                my $nl = $level == $prev ? "\n" : '';
                if ($nl && $cur) {
@@ -885,7 +887,7 @@ sub emit_topics {
                }
 
                $subj = PublicInbox::Hval->new($subj)->as_html;
-               $cur->[1] .= "<a\nhref=\"$mid/T/#u\"><b>$subj</b></a>\n";
+               $cur->[1] .= "<a\nhref=\"$href/T/#u\"><b>$subj</b></a>\n";
                $ts = fmt_ts($ts);
                my $attr = " $ts UTC";
 
@@ -894,8 +896,8 @@ sub emit_topics {
                $n = $n == 1 ? '' : " ($n+ messages)";
 
                if ($level == 0 || $attr ne $prev_attr) {
-                       my $mbox = qq(<a\nhref="$mid/t.mbox.gz">mbox.gz</a>);
-                       my $atom = qq(<a\nhref="$mid/t.atom">Atom</a>);
+                       my $mbox = qq(<a\nhref="$href/t.mbox.gz">mbox.gz</a>);
+                       my $atom = qq(<a\nhref="$href/t.atom">Atom</a>);
                        $pfx .= INDENT if $level > 0;
                        $cur->[1] .= $pfx . $attr . $n . " - $mbox / $atom\n";
                        $prev_attr = $attr;
@@ -903,13 +905,38 @@ sub emit_topics {
        }
        push @recent, $cur if $cur;
        @recent = map { $_->[1] } sort { $b->[0] <=> $a->[0] } @recent;
-       $fh->write(join('', @recent) . '</pre>');
+       $ctx->{-html_tip} = join('', '<pre>', @recent, '</pre>');
+       200;
 }
 
-sub emit_index_topics {
+sub index_nav { # callback for WwwStream
+       my (undef, $ctx) = @_;
+       delete $ctx->{qp} or return;
+       my ($next, $prev);
+       $next = $prev = '    ';
+       my $latest = '';
+
+       my $next_o = $ctx->{-next_o};
+       if ($next_o) {
+               $next = qq!<a\nhref="?o=$next_o"\nrel=next>next</a>!;
+       }
+       if (my $cur_o = $ctx->{-cur_o}) {
+               $latest = qq! <a\nhref=.>latest</a>!;
+
+               my $o = $cur_o - ($next_o - $cur_o);
+               if ($o > 0) {
+                       $prev = qq!<a\nhref="?o=$o"\nrel=prev>prev</a>!;
+               } elsif ($o == 0) {
+                       $prev = qq!<a\nhref=.\nrel=prev>prev</a>!;
+               }
+       }
+       "<hr><pre>page: $next $prev$latest</pre>";
+}
+
+sub index_topics {
        my ($ctx) = @_;
-       my ($off) = (($ctx->{cgi}->param('o') || '0') =~ /(\d+)/);
-       $ctx->{order} = [];
+       my ($off) = (($ctx->{qp}->{o} || '0') =~ /(\d+)/);
+       my $order = $ctx->{order} = [];
        $ctx->{subjs} = {};
        $ctx->{latest} = {};
        my $max = 25;
@@ -921,9 +948,9 @@ sub emit_index_topics {
                walk_thread(thread_results($sres), $ctx, *add_topic);
                $opts{offset} += $nr;
        }
-
-       emit_topics($ctx);
-       $opts{offset};
+       $ctx->{-next_o} = $opts{offset};
+       $ctx->{-cur_o} = $off;
+       PublicInbox::WwwStream->response($ctx, topics($ctx), *index_nav);
 }
 
 sub thread_adj_level {