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/Thread.pm | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/PublicInbox/Thread.pm') diff --git a/lib/PublicInbox/Thread.pm b/lib/PublicInbox/Thread.pm index 7dabf243..58efb8dc 100644 --- a/lib/PublicInbox/Thread.pm +++ b/lib/PublicInbox/Thread.pm @@ -12,6 +12,20 @@ if ($Mail::Thread::VERSION <= 2.55) { eval q(sub _container_class { 'PublicInbox::Thread::Container' }); } +sub sort_ts { + sort { + (eval { $a->topmost->message->header('X-PI-TS') } || 0) <=> + (eval { $b->topmost->message->header('X-PI-TS') } || 0) + } @_; +} + +sub rsort_ts { + sort { + (eval { $b->topmost->message->header('X-PI-TS') } || 0) <=> + (eval { $a->topmost->message->header('X-PI-TS') } || 0) + } @_; +} + package PublicInbox::Thread::Container; use strict; use warnings; -- cgit v1.2.3-24-ge0c7