about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-12-31 07:37:17 +0000
committerEric Wong <e@80x24.org>2015-12-31 07:37:17 +0000
commit3979330907a90821283ac21bc00f0f6506e90383 (patch)
tree1a3394c4dc3c4c287a61470a4e7bc6b060aa86a5 /lib
parent430a7799c319df9dcef0dae0a5aa0add0a40d6a1 (diff)
downloadpublic-inbox-3979330907a90821283ac21bc00f0f6506e90383.tar.gz
Oops, the rarely-accessed threaded search view was completely
broken.  Additionally, the normal threading depths were broken
when we attempted to go up-thread and replies got nested
improperly

Followup to commit be984ce279776d4513b4ca1bff05ebecafdd1bad
("view: thread using <ul> instead of <table>")
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/SearchView.pm18
-rw-r--r--lib/PublicInbox/View.pm57
2 files changed, 48 insertions, 27 deletions
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index ab3dddb4..5d4f4fe2 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -138,7 +138,7 @@ sub search_nav_bot {
 sub tdump {
         my ($cb, $res, $mset, $q, $ctx) = @_;
         my $fh = $cb->([200, ['Content-Type'=>'text/html; charset=UTF-8']]);
-        $fh->write($res);
+        $fh->write($res .= '</pre>');
         my %pct;
         my @m = map {
                 my $i = $_;
@@ -168,9 +168,15 @@ sub tdump {
         }
 
         my $git = $ctx->{git} ||= PublicInbox::Git->new($ctx->{git_dir});
-        my $state = { ctx => $ctx, anchor_idx => 0, pct => \%pct };
+        my $state = {
+                ctx => $ctx,
+                anchor_idx => 0,
+                pct => \%pct,
+                cur_level => 0
+        };
         $ctx->{searchview} = 1;
         tdump_ent($fh, $git, $state, $_, 0) for $th->rootset;
+        PublicInbox::View::thread_adj_level($fh, $state, 0);
         Email::Address->purge_cache;
 
         $fh->write(search_nav_bot($mset, $q). "\n\n" .
@@ -193,10 +199,13 @@ sub tdump_ent {
                 };
         }
         if ($mime) {
+                my $end =
+                  PublicInbox::View::thread_adj_level($fh, $state, $level);
                 PublicInbox::View::index_entry($fh, $mime, $level, $state);
+                $fh->write($end) if $end;
         } else {
                 my $mid = $node->messageid;
-                $fh->write(PublicInbox::View::ghost_table('', $mid, $level));
+                PublicInbox::View::ghost_flush($fh, $state, '', $mid, $level);
         }
         tdump_ent($fh, $git, $state, $node->child, $level + 1);
         tdump_ent($fh, $git, $state, $node->next, $level);
@@ -214,7 +223,8 @@ sub html_start {
 
         my $qh = $query->as_html;
         my $A = $q->qs_html(x => 'A', r => undef);
-        my $res = "<html><head><title>$qh - search results</title>" .
+        my $res = '<html><head>' . PublicInbox::Hval::STYLE .
+                "<title>$qh - search results</title>" .
                 qq{<link\nrel=alternate\ntitle="Atom feed"\n} .
                 qq!href="?$A"\ntype="application/atom+xml"/></head>! .
                 qq{<body><form\naction="">} .
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 20400470..fac0fcb1 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -176,7 +176,7 @@ sub emit_thread_html {
                 seen => $seen,
                 root_anchor => anchor_for($mid),
                 anchor_idx => 0,
-                max_level => 0,
+                cur_level => 0,
         };
 
         require PublicInbox::Git;
@@ -187,9 +187,8 @@ sub emit_thread_html {
         } else {
                 my $th = thread_results($msgs);
                 thread_entry(\$cb, $git, $state, $_, 0) for $th->rootset;
-                if (my $max = $state->{max_level}) {
-                        my $x = $max > 1 ? ('</ul></li>' x ($max-1)) : '';
-                        $cb->write($x . '</ul>');
+                if (my $max = $state->{cur_level}) {
+                        $cb->write(('</ul></li>' x ($max - 1)) . '</ul>');
                 }
         }
         $git = undef;
@@ -638,25 +637,37 @@ sub ghost_parent {
         qq{[parent not found: &lt;<a\nhref="$upfx$href/">$html</a>&gt;]};
 }
 
-sub __thread_adj_level {
-        my ($cb, $state, $level) = @_;
+sub thread_adj_level {
+        my ($fh, $state, $level) = @_;
 
-        return if $level <= 0; # flat output
-        my $max = $state->{max_level};
-        if ($level > $max) {
-                $state->{max_level} = $level;
-                $$cb->write(($max ? '<li>' : ''). '<ul><li>');
-        } else {
-                $$cb->write('<li>');
+        my $max = $state->{cur_level};
+        if ($level <= 0) {
+                return '' if $max == 0; # flat output
+
+                # reset existing lists
+                my $x = $max > 1 ? ('</ul></li>' x ($max - 1)) : '';
+                $fh->write($x . '</ul>');
+                $state->{cur_level} = 0;
+                return '';
         }
+        if ($level == $max) { # continue existing list
+                $fh->write('<li>');
+        } elsif ($level < $max) {
+                my $x = $max > 1 ? ('</ul></li>' x ($max - $level)) : '';
+                $fh->write($x .= '<li>');
+                $state->{cur_level} = $level;
+        } else { # ($level > $max) # start a new level
+                $state->{cur_level} = $level;
+                $fh->write(($max ? '<li>' : '') . '<ul><li>');
+        }
+        '</li>';
 }
 
-sub __ghost_flush {
-        my ($cb, $state, $upfx, $mid, $level) = @_;
+sub ghost_flush {
+        my ($fh, $state, $upfx, $mid, $level) = @_;
 
-        __thread_adj_level($cb, $state, $level);
-        $$cb->write('<pre>'. ghost_parent($upfx, $mid) .  '</pre>' .
-                        ($level > 0 ? '</li>' : ''));
+        my $end = thread_adj_level($fh, $state, $level);
+        $fh->write('<pre>'. ghost_parent($upfx, $mid) .  '</pre>' . $end);
 }
 
 sub __thread_entry {
@@ -671,16 +682,16 @@ sub __thread_entry {
         if ($state->{anchor_idx} == 0) {
                 thread_html_head($cb, $mime, $state, $level);
         }
-
+        my $fh = $$cb;
         if (my $ghost = delete $state->{ghost}) {
                 # n.b. ghost messages may only be parents, not children
                 foreach my $g (@$ghost) {
-                        __ghost_flush($cb, $state, '../../', @$g);
+                        ghost_flush($fh, $state, '../../', @$g);
                 }
         }
-        __thread_adj_level($cb, $state, $level);
-        index_entry($$cb, $mime, $level, $state);
-        $$cb->write('</li>') if $level > 0;
+        my $end = thread_adj_level($fh, $state, $level);
+        index_entry($fh, $mime, $level, $state);
+        $fh->write($end) if $end;
 
         1;
 }