X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FView.pm;h=895e4f278dfff8b76e1a1e5c5949cf42352c7364;hb=1cf5a6129b5ae4991275862aab539ddea812890a;hp=243528263b88954ee6c92ace894dfa56e8cca70e;hpb=55263c56cf41c87f8977cd6a6be65ac07b5cea87;p=public-inbox.git diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 24352826..895e4f27 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -14,7 +14,7 @@ use PublicInbox::MID qw(id_compress mids mids_for_index references $MID_EXTRACT); use PublicInbox::MsgIter; use PublicInbox::Address; -use PublicInbox::WwwStream; +use PublicInbox::WwwStream qw(html_oneshot); use PublicInbox::Reply; use PublicInbox::ViewDiff qw(flush_diff); use PublicInbox::Eml; @@ -27,45 +27,38 @@ use constant TCHILD => '` '; sub th_pfx ($) { $_[0] == 0 ? '' : TCHILD }; sub msg_page_i { - my ($ctx) = @_; - my $cur = delete $ctx->{smsg} or return; # undef: done - my $nxt; - if (my $over = $ctx->{-inbox}->over) { - $nxt = $ctx->{smsg} = $over->next_by_mid(@{$ctx->{next_arg}}); + my ($ctx, $eml) = @_; + if ($eml) { # called by WwwStream::async_eml or getline + my $smsg = $ctx->{smsg}; + $ctx->{smsg} = $ctx->{over}->next_by_mid(@{$ctx->{next_arg}}); + $ctx->{mhref} = ($ctx->{nr} || $ctx->{smsg}) ? + "../${\mid_href($smsg->{mid})}/" : ''; + my $hdr = $eml->header_obj; + my $obuf = $ctx->{obuf} = _msg_page_prepare_obuf($hdr, $ctx); + multipart_text_as_html($eml, $ctx); + delete $ctx->{obuf}; + $$obuf .= '
sub eml_entry { - my ($ctx, $smsg, $eml, $more) = @_; + my ($ctx, $eml, $more) = @_; + my $smsg = delete $ctx->{smsg}; my $subj = delete $smsg->{subject}; my $mid_raw = $smsg->{mid}; my $id = id_compress($mid_raw, 1); @@ -372,12 +366,12 @@ sub pre_thread { # walk_thread callback } sub thread_eml_entry { - my ($ctx, $level, $smsg, $eml) = @_; - my ($beg, $end) = thread_adj_level($ctx, $level); - $beg . '' . eml_entry($ctx, $smsg, $eml, 0) . '' . $end; + my ($ctx, $eml) = @_; + my ($beg, $end) = thread_adj_level($ctx, $ctx->{level}); + $beg . '' . eml_entry($ctx, $eml, 0) . '' . $end; } -sub next_in_queue ($;$) { +sub next_in_queue ($$) { my ($q, $ghost_ok) = @_; while (@$q) { my ($level, $smsg) = splice(@$q, 0, 2); @@ -389,29 +383,36 @@ sub next_in_queue ($;$) { } sub stream_thread_i { # PublicInbox::WwwStream::getline callback - my ($ctx) = @_; + my ($ctx, $eml) = @_; + goto &thread_eml_entry if $eml; # tail recursion return unless exists($ctx->{skel}); - my $nr = $ctx->{nr}++; - my ($level, $smsg) = next_in_queue($ctx->{-queue}, $nr); - - $smsg or return - join('', thread_adj_level($ctx, 0)) . ${delete $ctx->{skel}}; - - my $eml = $ctx->{-inbox}->smsg_eml($smsg) or return - ghost_index_entry($ctx, $level, $smsg); - - if ($nr == 0) { - $ctx->{-title_html} = ascii_html($smsg->{subject}); - $ctx->html_top . thread_eml_entry($ctx, $level, $smsg, $eml); - } else { - thread_eml_entry($ctx, $level, $smsg, $eml); + my $ghost_ok = $ctx->{nr}++; + while (1) { + my ($lvl, $smsg) = next_in_queue($ctx->{-queue}, $ghost_ok); + if ($smsg) { + if (exists $smsg->{blob}) { # next message for cat-file + $ctx->{level} = $lvl; + if (!$ghost_ok) { # first non-ghost + $ctx->{-title_html} = + ascii_html($smsg->{subject}); + $ctx->zmore($ctx->html_top); + } + return $smsg; + } + # buffer the ghost entry and loop + $ctx->zmore(ghost_index_entry($ctx, $lvl, $smsg)); + } else { # all done + $ctx->zmore(join('', thread_adj_level($ctx, 0))); + $ctx->zmore(${delete($ctx->{skel})}); + return; + } } } sub stream_thread ($$) { my ($rootset, $ctx) = @_; $ctx->{-queue} = [ map { (0, $_) } @$rootset ]; - PublicInbox::WwwStream::response($ctx, 200, \&stream_thread_i); + PublicInbox::WwwStream::aresponse($ctx, 200, \&stream_thread_i); } # /$INBOX/$MESSAGE_ID/t/ @@ -451,23 +452,26 @@ sub thread_html { # flat display: lazy load the full message from smsg $ctx->{msgs} = $msgs; $ctx->{-html_tip} = ''; - PublicInbox::WwwStream::response($ctx, 200, \&thread_html_i); + PublicInbox::WwwStream::aresponse($ctx, 200, \&thread_html_i); } sub thread_html_i { # PublicInbox::WwwStream::getline callback - my ($ctx) = @_; - my $msgs = $ctx->{msgs} or return; - while (my $smsg = shift @$msgs) { - my $eml = $ctx->{-inbox}->smsg_eml($smsg) or next; + my ($ctx, $eml) = @_; + if ($eml) { + my $smsg = $ctx->{smsg}; if (exists $ctx->{-html_tip}) { $ctx->{-title_html} = ascii_html($smsg->{subject}); - return $ctx->html_top . - eml_entry($ctx, $smsg, $eml, scalar @$msgs); + $ctx->zmore($ctx->html_top); + } + return eml_entry($ctx, $eml, scalar @{$ctx->{msgs}}); + } else { + while (my $smsg = shift @{$ctx->{msgs}}) { + return $smsg if exists($smsg->{blob}); } - return eml_entry($ctx, $smsg, $eml, scalar @$msgs); + my $skel = delete($ctx->{skel}) or return; # all done + $ctx->zmore($$skel); + undef; } - my ($skel) = delete @$ctx{qw(skel msgs)}; - $$skel; } sub multipart_text_as_html { @@ -1160,12 +1164,6 @@ sub pagination_footer ($$) { "page: $next$prev"; } -sub index_nav { # callback for WwwStream::getline - my ($ctx) = @_; - return $ctx->html_top if exists $ctx->{-html_tip}; - pagination_footer($ctx, '.') -} - sub paginate_recent ($$) { my ($ctx, $lim) = @_; my $t = $ctx->{qp}->{t} || ''; @@ -1214,7 +1212,8 @@ sub index_topics { if (@$msgs) { walk_thread(thread_results($ctx, $msgs), $ctx, \&acc_topic); } - PublicInbox::WwwStream::response($ctx, dump_topics($ctx), \&index_nav); + html_oneshot($ctx, dump_topics($ctx), \pagination_footer($ctx, '.')); + } sub thread_adj_level {