user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] view: allow topics to be "bumped" by new replies
Date: Tue, 12 Apr 2016 21:22:41 +0000	[thread overview]
Message-ID: <20160412212241.24262-1-e@80x24.org> (raw)

This ought to prevent new replies from getting lost for readers
relying on the WWW index interface.
---
 lib/PublicInbox/View.pm | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 070240e..f58099d 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -843,13 +843,6 @@ sub sort_ts {
 	} @_;
 }
 
-sub rsort_ts {
-	sort {
-		(eval { $b->topmost->message->header('X-PI-TS') } || 0) <=>
-		(eval { $a->topmost->message->header('X-PI-TS') } || 0)
-	} @_;
-}
-
 # accumulate recent topics if search is supported
 # returns 1 if done, undef if not
 sub add_topic {
@@ -884,16 +877,18 @@ sub add_topic {
 	add_topic($state, $node->next, $level);
 }
 
-sub dump_topics {
+sub emit_topics {
 	my ($state) = @_;
 	my $order = $state->{order};
 	my $subjs = $state->{subjs};
 	my $latest = $state->{latest};
-	return "\n[No topics in range]</pre>" unless (scalar @$order);
-	my $dst = '';
+	my $fh = $state->{fh};
+	return $fh->write("\n[No topics in range]</pre>") unless scalar @$order;
 	my $pfx;
 	my $prev = 0;
 	my $prev_attr = '';
+	my $cur;
+	my @recent;
 	while (defined(my $info = shift @$order)) {
 		my ($level, $subj) = @$info;
 		my $n = delete $subjs->{$subj};
@@ -902,8 +897,16 @@ sub dump_topics {
 		$subj = PublicInbox::Hval->new($subj)->as_html;
 		$pfx = indent_for($level);
 		my $nl = $level == $prev ? "\n" : '';
+		if ($nl && $cur) {
+			push @recent, $cur;
+			$cur = undef;
+		}
+		$cur ||= [ $ts, '' ];
 		my $dot = $level == 0 ? '' : '` ';
-		$dst .= "$nl$pfx$dot<a\nhref=\"$mid/t/#u\"><b>$subj</b></a>\n";
+		$cur->[0] = $ts if $ts > $cur->[0];
+		$cur->[1] .= "$nl$pfx$dot<a\nhref=\"$mid/t/#u\"><b>";
+		$cur->[1] .= $subj;
+		$cur->[1] .= "</b></a>\n";
 
 		$ts = fmt_ts($ts);
 		my $attr = " $ts UTC";
@@ -916,11 +919,13 @@ sub dump_topics {
 			my $mbox = qq(<a\nhref="$mid/t.mbox.gz">mbox.gz</a>);
 			my $atom = qq(<a\nhref="$mid/t.atom">Atom</a>);
 			$pfx .= INDENT if $level > 0;
-			$dst .= $pfx . $attr . $n . " - $mbox / $atom\n";
+			$cur->[1] .= $pfx . $attr . $n . " - $mbox / $atom\n";
 			$prev_attr = $attr;
 		}
 	}
-	$dst .= '</pre>';
+	push @recent, $cur if $cur;
+	@recent = map { $_->[1] } sort { $b->[0] <=> $a->[0] } @recent;
+	$fh->write(join('', @recent) . '</pre>');
 }
 
 sub emit_index_topics {
@@ -936,13 +941,13 @@ sub emit_index_topics {
 		my $sres = $state->{srch}->query('', \%opts);
 		my $nr = scalar @{$sres->{msgs}} or last;
 
-		for (rsort_ts(thread_results(load_results($sres), 1)->rootset)){
+		for (thread_results(load_results($sres), 1)->rootset) {
 			add_topic($state, $_, 0);
 		}
 		$opts{offset} += $nr;
 	}
 
-	$state->{fh}->write(dump_topics($state));
+	emit_topics($state);
 	$opts{offset};
 }
 
-- 
EW


                 reply	other threads:[~2016-04-12 21:22 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=20160412212241.24262-1-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).