Rejecting this, as it's too much clutter and options.
People who really want a flat view should use the Atom feed.
---
 lib/PublicInbox/SearchView.pm | 109 ++++++++++++++++++++++++++++--------------
 1 file changed, 72 insertions(+), 37 deletions(-)

diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index b65351a..f0c6670 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -44,7 +44,10 @@ sub sres_top_html {
                $res .= search_nav_top($mset, $q);
                if ($x eq 't') {
                        return sub { tdump($_[0], $res, $mset, $q, $ctx) };
+               } elsif ($x eq 'f') {
+                       return sub { fdump($_[0], $res, $mset, $q, $ctx) };
                }
+
                $res .= "\n\n";
                dump_mset(\$res, $mset);
                $res .= search_nav_bot($mset, $q) . "\n\n" . foot($ctx);
@@ -96,17 +99,24 @@ sub search_nav_top {
                $rv .= qq{<b>date</b>|<a\nhref="?$d">relevance</a>};
        }
 
-       $rv .= ']  view[';
+       $rv .= ']  view: [';
 
        my $x = $q->{x};
+       my $t = $q->qs_html(x => 't');
+       my $s = $q->qs_html(x => '');
+       my $f = $q->qs_html(x => 'f');
        if ($x eq '') {
-               my $t = $q->qs_html(x => 't');
-               $rv .= qq{<b>summary</b>|};
-               $rv .= qq{<a\nhref="?$t">threaded</a>}
-       } elsif ($q->{x} eq 't') {
-               my $s = $q->qs_html(x => '');
-               $rv .= qq{<a\nhref="?$s">summary</a>|};
-               $rv .= qq{<b>threaded</b>};
+               $rv .= qq{<b>short</b>|} .
+                       qq{<a\nhref="?$t">threaded</a>|} .
+                       qq{<a\nhref="?$f">flat</a>};
+       } elsif ($x eq 't') {
+               $rv .= qq{<a\nhref="?$s">short</a>|} .
+                       qq{<b>threaded</b>|} .
+                       qq{<a\nhref="?$f">flat</a>};
+       } elsif ($x eq 'f') {
+               $rv .= qq{<a\nhref="?$s">short</a>|} .
+                       qq{<a\nhref="?$t">threaded</a>|} .
+                       qq{<b>flat</b>};
        }
        my $A = $q->qs_html(x => 'A');
        $rv .= qq{|<a\nhref="?$A">Atom</a>};
@@ -136,8 +146,8 @@ sub search_nav_bot {
        $rv;
 }
 
-sub tdump {
-       my ($cb, $res, $mset, $q, $ctx) = @_;
+sub dump_prepare {
+       my ($cb, $res, $mset, $ctx) = @_;
        my $fh = $cb->([200, ['Content-Type'=>'text/html; charset=UTF-8']]);
        $fh->write($res);
        my %pct;
@@ -148,56 +158,81 @@ sub tdump {
                $m = $m->mini_mime;
                $m;
        } ($mset->items);
+       my $state = { ctx => $ctx, anchor_idx => 0, pct => \%pct };
+       $ctx->{searchview} = 1;
+       require PublicInbox::GitCatFile;
+       my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+       $state->{git} = $git;
+
+       ($fh, \@m, $git, $state);
+}
+
+sub dump_end {
+       my ($fh, $mset, $q, $ctx) = @_;
+       Email::Address->purge_cache;
+
+       $fh->write(search_nav_bot($mset, $q). "\n\n" .
+                       foot($ctx). '</pre></body></html>');
+       $fh->close;
+}
+
+sub fdump {
+       my ($cb, $res, $mset, $q, $ctx) = @_;
+       my ($fh, $m, $git, $state) = dump_prepare($cb, $res, $mset, $ctx);
+       mime_dump($fh, $git, $_, 0, $state) for (@$m);
+       dump_end($fh, $mset, $q, $ctx);
+}
+
+sub do_thread {
+       my ($m, $pct, $q) = @_;
 
        require PublicInbox::Thread;
-       my $th = PublicInbox::Thread->new(@m);
+       my $th = PublicInbox::Thread->new(@$m);
        {
                no warnings 'once';
                $Mail::Thread::nosubject = 0;
+               $th->thread;
        }
-       $th->thread;
        if ($q->{r}) {
                $th->order(sub {
-                       sort { (eval { $pct{$b->topmost->messageid} } || 0)
+                       sort { (eval { $pct->{$b->topmost->messageid} } || 0)
                                        <=>
-                               (eval { $pct{$a->topmost->messageid} } || 0)
+                               (eval { $pct->{$a->topmost->messageid} } || 0)
                        } @_;
                });
        } else {
                no warnings 'once';
                $th->order(*PublicInbox::View::rsort_ts);
        }
+       $th;
+}
 
-       require PublicInbox::GitCatFile;
-       my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
-       my $state = { ctx => $ctx, anchor_idx => 0, pct => \%pct };
-       $ctx->{searchview} = 1;
+sub tdump {
+       my ($cb, $res, $mset, $q, $ctx) = @_;
+       my ($fh, $m, $git, $state) = dump_prepare($cb, $res, $mset, $ctx);
+       my $th = do_thread($m, $state->{pct}, $q);
        tdump_ent($fh, $git, $state, $_, 0) for $th->rootset;
-       $git = undef;
-       Email::Address->purge_cache;
+       dump_end($fh, $mset, $q, $ctx);
+}
 
-       $fh->write(search_nav_bot($mset, $q). "\n\n" .
-                       foot($ctx). '</pre></body></html>');
+sub mime_dump {
+       my ($fh, $git, $mime, $level, $state) = @_;
 
-       $fh->close;
+       # lazy load the full message from mini_mime:
+       my $mid = $mime->header('Message-ID');
+       $mime = eval {
+               my $path = mid2path(mid_clean($mid));
+               Email::MIME->new($git->cat_file('HEAD:'.$path));
+       };
+       PublicInbox::View::index_entry($fh, $mime, $level, $state) if $mime;
+       $mime;
 }
 
 sub tdump_ent {
        my ($fh, $git, $state, $node, $level) = @_;
        return unless $node;
-       my $mime = $node->message;
-
-       if ($mime) {
-               # lazy load the full message from mini_mime:
-               my $mid = $mime->header('Message-ID');
-               $mime = eval {
-                       my $path = mid2path(mid_clean($mid));
-                       Email::MIME->new($git->cat_file('HEAD:'.$path));
-               };
-       }
-       if ($mime) {
-               PublicInbox::View::index_entry($fh, $mime, $level, $state);
-       } else {
+
+       unless (mime_dump($fh, $git, $node->message, $level, $state)) {
                my $mid = $node->messageid;
                $fh->write(PublicInbox::View::ghost_table('', $mid, $level));
        }
@@ -295,7 +330,7 @@ sub qs_html {
                $qs .= "&amp;r";
        }
        if (my $x = $self->{x}) {
-               $qs .= "&amp;x=$x" if ($x eq 't' || $x eq 'A');
+               $qs .= "&amp;x=$x" if ($x =~ /\A(?:A|t|f)\z/);
        }
        $qs;
 }
-- 
EW

--
unsubscribe: meta+unsubscr...@public-inbox.org
archive: http://public-inbox.org/meta/

Reply via email to