From 7ce4210ceb2a150e20e48676d8b635f6d2ed471f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 2 Sep 2015 02:37:21 +0000 Subject: view: pre-anchor entries for flat view This will allow users to navigate the flat view without making extra HTTP requests. --- lib/PublicInbox/View.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 0331b62c..98fc133d 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -167,9 +167,10 @@ sub emit_thread_html { return missing_thread($cb) if $nr == 0; my $flat = $ctx->{flat}; my $orig_cb = $cb; + my $seen = {}; my $state = { ctx => $ctx, - seen => {}, + seen => $seen, root_anchor => anchor_for($mid), anchor_idx => 0, }; @@ -177,6 +178,7 @@ sub emit_thread_html { require PublicInbox::GitCatFile; my $git = PublicInbox::GitCatFile->new($ctx->{git_dir}); if ($flat) { + pre_anchor_entry($seen, $_) for (@$msgs); __thread_entry(\$cb, $git, $state, $_, 0) for (@$msgs); } else { my $th = thread_results($msgs); @@ -580,6 +582,12 @@ sub thread_html_head { $$cb->write("$s"); } +sub pre_anchor_entry { + my ($seen, $mime) = @_; + my $id = anchor_for($mime->header('Message-ID')); + $seen->{$id} = "#$id"; # save the anchor for children, later +} + sub __thread_entry { my ($cb, $git, $state, $mime, $level) = @_; -- cgit v1.2.3-24-ge0c7