]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/View.pm
viewvcs: use shorter and simpler ctx->html_done
[public-inbox.git] / lib / PublicInbox / View.pm
index 11a94ba938636ce28bd8d5373d5e2b3d50c811c6..c6fd05cce3a59e8327c4959db3f7480ff759b0b7 100644 (file)
@@ -38,14 +38,12 @@ sub msg_page_i {
                                : $ctx->gone('over');
                $ctx->{mhref} = ($ctx->{nr} || $ctx->{smsg}) ?
                                "../${\mid_href($smsg->{mid})}/" : '';
-               my $obuf = _msg_page_prepare_obuf($eml, $ctx);
-               if (length($$obuf)) {
+               if (_msg_page_prepare_obuf($eml, $ctx)) {
                        multipart_text_as_html($eml, $ctx);
-                       $$obuf .= '</pre><hr>';
+                       ${$ctx->{obuf}} .= '</pre><hr>';
                }
-               delete $ctx->{obuf};
-               $$obuf .= html_footer($ctx, $ctx->{first_hdr}) if !$ctx->{smsg};
-               $$obuf;
+               html_footer($ctx, $ctx->{first_hdr}) if !$ctx->{smsg};
+               delete($ctx->{obuf}) // \'';
        } else { # called by WwwStream::async_next or getline
                $ctx->{smsg}; # may be undef
        }
@@ -58,14 +56,12 @@ sub no_over_html ($) {
        my $eml = PublicInbox::Eml->new($bref);
        $ctx->{mhref} = '';
        PublicInbox::WwwStream::init($ctx);
-       my $obuf = _msg_page_prepare_obuf($eml, $ctx);
-       if (length($$obuf)) {
+       if (_msg_page_prepare_obuf($eml, $ctx)) { # sets {-title_html}
                multipart_text_as_html($eml, $ctx);
-               $$obuf .= '</pre><hr>';
+               ${$ctx->{obuf}} .= '</pre><hr>';
        }
-       delete $ctx->{obuf};
-       eval { $$obuf .= html_footer($ctx, $eml) };
-       html_oneshot($ctx, 200, $$obuf);
+       html_footer($ctx, $eml);
+       $ctx->html_done;
 }
 
 # public functions: (unstable)
@@ -84,7 +80,7 @@ sub msg_page {
        # allow user to easily browse the range around this message if
        # they have ->over
        $ctx->{-t_max} = $smsg->{ts};
-       PublicInbox::WwwStream::aresponse($ctx, 200, \&msg_page_i);
+       PublicInbox::WwwStream::aresponse($ctx, \&msg_page_i);
 }
 
 # /$INBOX/$MESSAGE_ID/#R
@@ -436,7 +432,7 @@ sub stream_thread_i { # PublicInbox::WwwStream::getline callback
 sub stream_thread ($$) {
        my ($rootset, $ctx) = @_;
        @{$ctx->{-queue}} = map { (0, $_) } @$rootset;
-       PublicInbox::WwwStream::aresponse($ctx, 200, \&stream_thread_i);
+       PublicInbox::WwwStream::aresponse($ctx, \&stream_thread_i);
 }
 
 # /$INBOX/$MSGID/t/ and /$INBOX/$MSGID/T/
@@ -487,7 +483,7 @@ EOF
        # flat display: lazy load the full message from smsg
        $ctx->{msgs} = $msgs;
        $ctx->{-html_tip} = '<pre>';
-       PublicInbox::WwwStream::aresponse($ctx, 200, \&thread_html_i);
+       PublicInbox::WwwStream::aresponse($ctx, \&thread_html_i);
 }
 
 sub thread_html_i { # PublicInbox::WwwStream::getline callback
@@ -669,7 +665,7 @@ sub _msg_page_prepare_obuf {
        if ($nr) { # unlikely
                if ($ctx->{chash} eq content_hash($eml)) {
                        warn "W: BUG? @$mids not deduplicated properly\n";
-                       return \$rv;
+                       return;
                }
                $rv .=
 "<pre>WARNING: multiple messages have this Message-ID\n</pre><pre>";
@@ -717,7 +713,13 @@ sub _msg_page_prepare_obuf {
        for my $v ($eml->header('Date')) {
                $v = ascii_html($v);
                obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx; # possible :P
-               $rv .= qq{Date: $v\t<a\nhref="#r">[thread overview]</a>\n};
+               $rv .= qq{Date: $v\n};
+       }
+       # [thread overview] link is typically added after Date,
+       # but added after Subject, or even nothing.
+       if ($have_over) {
+               chop $rv; # drop "\n", or noop if $rv eq ''
+               $rv .= qq{\t<a\nhref="#r">[thread overview]</a>\n};
        }
        if (!$nr) { # first (and only) message, common case
                $ctx->{-title_html} = join(' - ', @title);
@@ -740,7 +742,7 @@ sub _msg_page_prepare_obuf {
        }
        _parent_headers($ctx, $eml);
        $rv .= "\n";
-       \$rv;
+       1;
 }
 
 sub SKEL_EXPAND () {
@@ -821,13 +823,11 @@ EOM
        }
 }
 
-# returns a string buffer
+# appends to obuf
 sub html_footer {
        my ($ctx, $hdr) = @_;
        my $upfx = '../';
-       my $skel;
-       my $rv = '<pre>';
-       my $related;
+       my ($related, $skel);
        my $qry = delete $ctx->{-qry};
        if ($qry && $ctx->{ibx}->isrch) {
                my $q = ''; # search for either ancestor or descendent patches
@@ -890,15 +890,15 @@ EOF
                } elsif ($u) { # unlikely
                        $parent = " <a\nhref=\"$u\"\nrel=prev>parent</a>";
                }
-               $rv .= "$next $prev$parent ";
+               ${$ctx->{obuf}} .= "<pre>$next $prev$parent ";
        } else { # unindexed inboxes w/o over
+               ${$ctx->{obuf}} .= '<pre>';
                $skel = qq( <a\nhref="$upfx">latest</a>);
        }
-       $rv .= qq(<a\nhref="#R">reply</a>);
-       $rv .= $skel;
-       $rv .= '</pre>';
-       $rv .= $related // '';
-       $rv .= msg_reply($ctx, $hdr);
+       ${$ctx->{obuf}} .= qq(<a\nhref="#R">reply</a>);
+       # $skel may be big for big threads, don't append it to obuf
+       $skel .= '</pre>' . ($related // '');
+       $ctx->zmore($skel .= msg_reply($ctx, $hdr)); # flushes obuf
 }
 
 sub linkify_ref_no_over {
@@ -1256,7 +1256,7 @@ sub paginate_recent ($$) {
                        my $n = strftime('%Y-%m-%d %H:%M:%S', gmtime($newest));
                        my $o = strftime('%Y-%m-%d %H:%M:%S', gmtime($oldest));
                        $ctx->{t_note} = <<EOM;
- messages from $o to $n UTC, [<a href="#nav">more...</a>]
+ messages from $o to $n UTC [<a href="#nav">more...</a>]
 EOM
                        my $s = ts2str($newest);
                        $ctx->{prev_page} = qq[<a\nhref="?t=$s-"\nrel=prev>] .