]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
view: allow expanding directly to "nested" view
[public-inbox.git] / lib / PublicInbox / View.pm
index 41f1321e4251e6c80e322c3dd69004b3c9524b4f..65d7d019b3018d40f1880b9d7e4bfe62722cfe7c 100644 (file)
@@ -61,7 +61,8 @@ sub msg_reply {
                $info = qq(\n  List information: <a\nhref="$url">$url</a>\n);
        }
 
-       my ($arg, $link) = PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
+       my ($arg, $link, $reply_to_all) =
+                       PublicInbox::Reply::mailto_arg_link($ibx, $hdr);
 
        # mailto: link only works if address obfuscation is disabled
        if ($link) {
@@ -69,9 +70,10 @@ sub msg_reply {
 
 * If your mail client supports setting the <b>In-Reply-To</b> header
   via mailto: links, try the <a
-href="$link">mailto: link</a></pre>
+href="$link">mailto: link</a>
 EOF
        }
+
        push @$arg, '/path/to/YOUR_REPLY';
        $arg = ascii_html(join(" \\\n    ", '', @$arg));
        <<EOF
@@ -83,21 +85,21 @@ href=#t>this message</a> 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: <a
+  and $reply_to_all from there: <a
 href=raw>mbox</a>
 
   Avoid top-posting and favor interleaved quoting:
   <a
 href="$p_url">$p_url</a>
 $info
-* Reply to all the recipients using the <b>--to</b>, <b>--cc</b>,
-  and <b>--in-reply-to</b> switches of git-send-email(1):
+* Reply using the <b>--to</b>, <b>--cc</b>, and <b>--in-reply-to</b>
+  switches of git-send-email(1):
 
   git send-email$arg
 
   <a
 href="$se_url">$se_url</a>
-$link
+$link</pre>
 EOF
 }
 
@@ -574,26 +576,27 @@ sub thread_skel {
        my $mid = mid_clean($hdr->header_raw('Message-ID'));
        my $sres = $srch->get_thread($mid);
        my $nr = $sres->{total};
-       my $expand = qq(<a\nhref="${tpfx}T/#u">expand</a> ) .
-                       qq(/ <a\nhref="${tpfx}t.mbox.gz">mbox.gz</a> ) .
-                       qq(/ <a\nhref="${tpfx}t.atom">Atom feed</a>);
+       my $expand = qq(expand[<a\nhref="${tpfx}T/#u">flat</a>) .
+                       qq(|<a\nhref="${tpfx}t/#u">nested</a>]  ) .
+                       qq(<a\nhref="${tpfx}t.mbox.gz">mbox.gz</a>  ) .
+                       qq(<a\nhref="${tpfx}t.atom">Atom feed</a>);
 
        my $parent = in_reply_to($hdr);
        $$dst .= "\n<b>Thread overview: </b>";
        if ($nr <= 1) {
                if (defined $parent) {
-                       $$dst .= "($expand)\n ";
+                       $$dst .= "$expand\n ";
                        $$dst .= ghost_parent("$tpfx../", $parent) . "\n";
                } else {
-                       $$dst .= "[no followups, yet] ($expand)\n";
+                       $$dst .= "[no followups] $expand\n";
                }
                $ctx->{next_msg} = undef;
                $ctx->{parent_msg} = $parent;
                return;
        }
 
-       $$dst .= "$nr+ messages in thread ($expand";
-       $$dst .= qq! / <a\nhref="#b">[top]</a>)\n!;
+       $$dst .= "$nr+ messages $expand";
+       $$dst .= qq!  <a\nhref="#b">top</a>\n!;
 
        my $subj = $hdr->header('Subject');
        defined $subj or $subj = '';
@@ -755,6 +758,25 @@ sub _msg_date {
 
 sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
 
+sub dedupe_subject {
+       my ($prev_subj, $subj, $val) = @_;
+
+       my $omit = ''; # '"' denotes identical text omitted
+       my (@prev_pop, @curr_pop);
+       while (@$prev_subj && @$subj && $subj->[-1] eq $prev_subj->[-1]) {
+               push(@prev_pop, pop(@$prev_subj));
+               push(@curr_pop, pop(@$subj));
+               $omit ||= $val;
+       }
+       pop @$subj if @$subj && $subj->[-1] =~ /^re:\s*/i;
+       if (scalar(@curr_pop) == 1) {
+               $omit = '';
+               push @$prev_subj, @prev_pop;
+               push @$subj, @curr_pop;
+       }
+       $omit;
+}
+
 sub skel_dump {
        my ($ctx, $level, $node) = @_;
        my $smsg = $node->{smsg} or return _skel_ghost($ctx, $level, $node);
@@ -798,13 +820,7 @@ sub skel_dump {
        # so we do not show redundant text at the end.
        my $prev_subj = $ctx->{prev_subj} || [];
        $ctx->{prev_subj} = [ @subj ];
-       my $omit = ''; # '"' denotes identical text omitted
-       while (@$prev_subj && @subj && $subj[-1] eq $prev_subj->[-1]) {
-               pop @$prev_subj;
-               pop @subj;
-               $omit ||= '&#34; ';
-       }
-       pop @subj if @subj && $subj[-1] =~ /^re:\s*/i;
+       my $omit = dedupe_subject($prev_subj, \@subj, '&#34; ');
        my $end;
        if (@subj) {
                my $subj = join(' ', @subj);
@@ -944,14 +960,7 @@ sub dump_topics {
                        $mid = delete $seen->{$subj};
                        my @subj = split(/ /, $srch->subject_normalized($subj));
                        my @next_prev = @subj; # full copy
-                       my $omit = ''; # '"' denotes identical text omitted
-                       while (@$prev_subj && @subj &&
-                                       $subj[-1] eq $prev_subj->[-1]) {
-                               pop @$prev_subj;
-                               pop @subj;
-                               $omit ||= ' &#34;';
-                       }
-                       pop @subj if @subj && $subj[-1] =~ /^re:\s*/i;
+                       my $omit = dedupe_subject($prev_subj, \@subj, ' &#34;');
                        $prev_subj = \@next_prev;
                        $subj = ascii_html(join(' ', @subj));
                        obfuscate_addrs($obfs_ibx, $subj) if $obfs_ibx;