about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-10-14 09:00:01 +0000
committerEric Wong <e@80x24.org>2016-10-14 21:12:42 +0000
commit123031737a09edb3297e0fc6ea9e566fc2fecdf5 (patch)
tree18324713168c363c29ed6b2d918f637184dad1d6
parentf2b07568e623c2a0aff4d0135617a26c887d2755 (diff)
downloadpublic-inbox-123031737a09edb3297e0fc6ea9e566fc2fecdf5.tar.gz
This reverts commit 3c9dd6619f825f0515e7e4afa1bd55c99c1a68d3
("thread: fix sorting without topmost")
and reinstates the "topmost" routine for sorting purposes.
-rw-r--r--lib/PublicInbox/SearchThread.pm10
-rw-r--r--lib/PublicInbox/SearchView.pm5
-rw-r--r--lib/PublicInbox/View.pm4
3 files changed, 15 insertions, 4 deletions
diff --git a/lib/PublicInbox/SearchThread.pm b/lib/PublicInbox/SearchThread.pm
index 24a56d2d..fe70406b 100644
--- a/lib/PublicInbox/SearchThread.pm
+++ b/lib/PublicInbox/SearchThread.pm
@@ -98,6 +98,16 @@ sub new {
         }, $_[0];
 }
 
+sub topmost {
+        my ($self) = @_;
+        my @q = ($self);
+        while (my $cont = shift @q) {
+                return $cont if $cont->{smsg};
+                push @q, values %{$cont->{children}};
+        }
+        undef;
+}
+
 sub add_child {
         my ($self, $child) = @_;
         croak "Cowardly refusing to become my own parent: $self"
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index cfe6dfff..ebeb41f7 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -155,8 +155,9 @@ sub mset_thread {
         $th->thread;
         if ($q->{r}) { # order by relevance
                 $th->order(sub {
-                        [ sort { ( $pct{$b->{id}} || 0) <=>
-                                 ( $pct{$a->{id}} || 0)
+                        [ sort { (eval { $pct{$b->topmost->{id}} } || 0)
+                                        <=>
+                                (eval { $pct{$a->topmost->{id}} } || 0)
                         } @{$_[0]} ];
                 });
         } else { # order by time (default for threaded view)
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 0f00458e..5d5808fa 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -852,8 +852,8 @@ sub skel_dump {
 
 sub sort_ts {
         [ sort {
-                (eval { $a->{smsg}->ts } || 0) <=>
-                (eval { $b->{smsg}->ts } || 0)
+                (eval { $a->topmost->{smsg}->ts } || 0) <=>
+                (eval { $b->topmost->{smsg}->ts } || 0)
         } @{$_[0]} ];
 }