From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Cc: Eric Wong <e@80x24.org>
Subject: [PATCH] feed: extract subroutines for threading
Date: Mon, 20 Jul 2015 21:53:14 +0000 [thread overview]
Message-ID: <1437429194-8111-1-git-send-email-e@80x24.org> (raw)
We'll be using this in the future for displaying per-thread
views.
---
lib/PublicInbox/Feed.pm | 49 +++++++++++++++++++++++++++++++------------------
1 file changed, 31 insertions(+), 18 deletions(-)
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index 3c0ec86..f7c2f32 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -61,13 +61,7 @@ sub generate_html_index {
my $git_dir = $args->{git_dir};
my $git = PublicInbox::GitCatFile->new($git_dir);
my ($first, $last) = each_recent_blob($args, sub {
- my $mime = do_cat_mail($git, $_[0]) or return 0;
-
- my $t = eval { str2time($mime->header('Date')) };
- defined($t) or $t = 0;
- $mime->header_set('X-PI-Date', $t);
- push @messages, $mime;
- 1;
+ mime_load_for_sort($git, $_[0], \@messages);
});
$git = undef; # destroy pipes.
@@ -79,20 +73,11 @@ sub generate_html_index {
'</head><body>' . PRE_WRAP;
# sort child messages in chronological order
- $th->order(sub {
- sort {
- $a->topmost->message->header('X-PI-Date') <=>
- $b->topmost->message->header('X-PI-Date')
- } @_;
- });
+ $th->order(sub { mime_sort_children(@_) });
# except we sort top-level messages reverse chronologically
my $state = [ time, {}, $first, 0 ];
- for (sort { (eval { $b->message->header('X-PI-Date') } || 0) <=>
- (eval { $a->message->header('X-PI-Date') } || 0)
- } $th->rootset) {
- dump_msg($_, 0, \$html, $state);
- }
+ for (mime_sort_roots($th)) { dump_msg($_, 0, \$html, $state) }
Email::Address->purge_cache;
my $footer = nav_footer($args->{cgi}, $last, $feed_opts, $state);
@@ -308,4 +293,32 @@ sub do_cat_mail {
$@ ? undef : $mime;
}
+sub mime_load_for_sort {
+ my ($git, $path, $messages) = @_;
+ my $mime = do_cat_mail($git, $path) or return 0;
+
+ my $t = eval { str2time($mime->header('Date')) };
+ defined($t) or $t = 0;
+ $mime->header_set('X-PI-Date', $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;
--
EW
reply other threads:[~2015-07-20 21:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1437429194-8111-1-git-send-email-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).