From f79d00b03dfa4f3f3c13bee4654d243c1d2fcd97 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 15 Aug 2015 23:41:21 +0000 Subject: thread: common sorting code We'll be sharing the same threading, so it makes sense to sort replies using the same code and message headers without repeating ourselves. This also standardizes on sorting on X-PI-TS (Unix epoch in seconds) instead over using X-PI-Date differently in two different places --- lib/PublicInbox/Feed.pm | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'lib/PublicInbox/Feed.pm') diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm index f7c2f329..b5325597 100644 --- a/lib/PublicInbox/Feed.pm +++ b/lib/PublicInbox/Feed.pm @@ -73,11 +73,13 @@ sub generate_html_index { '' . PRE_WRAP; # sort child messages in chronological order - $th->order(sub { mime_sort_children(@_) }); + $th->order(*PublicInbox::Thread::sort_ts); # except we sort top-level messages reverse chronologically my $state = [ time, {}, $first, 0 ]; - for (mime_sort_roots($th)) { dump_msg($_, 0, \$html, $state) } + for (PublicInbox::Thread::rsort_ts($th->rootset)) { + dump_msg($_, 0, \$html, $state) + } Email::Address->purge_cache; my $footer = nav_footer($args->{cgi}, $last, $feed_opts, $state); @@ -299,26 +301,9 @@ sub mime_load_for_sort { my $t = eval { str2time($mime->header('Date')) }; defined($t) or $t = 0; - $mime->header_set('X-PI-Date', $t); + $mime->header_set('X-PI-TS', $t); push @$messages, $mime; 1; } -# children are chronological -sub mime_sort_children { - sort { - $a->topmost->message->header('X-PI-Date') <=> - $b->topmost->message->header('X-PI-Date') - } @_; -} - -# parents are reverse chronological -sub mime_sort_roots { - my ($th) = @_; - sort { - (eval { $b->message->header('X-PI-Date') } || 0) <=> - (eval { $a->message->header('X-PI-Date') } || 0) - } $th->rootset; -} - 1; -- cgit v1.2.3-24-ge0c7