]> Sergey Matveev's repositories - public-inbox.git/commitdiff
view: pre-anchor entries for flat view
authorEric Wong <e@80x24.org>
Wed, 2 Sep 2015 02:37:21 +0000 (02:37 +0000)
committerEric Wong <e@80x24.org>
Wed, 2 Sep 2015 06:50:23 +0000 (06:50 +0000)
This will allow users to navigate the flat view without making extra
HTTP requests.

lib/PublicInbox/View.pm

index 0331b62c68b0800a3e1af6357d0469e801ceaa41..98fc133db9b4ed28f16ac8e8ade6c0cd3b236b31 100644 (file)
@@ -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("<html><head><title>$s</title></head><body>");
 }
 
+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) = @_;