From 6c853f5256f3a324c018a37a9e8a6b9fc8fdc063 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 27 Aug 2020 22:04:59 +0000 Subject: www: improve navigation around contemporary threads Sometimes it's useful to quickly get to threads and messages which are contemporaries of the current thread/message being focused on. This hopefully improves navigation by making: a) the top line (where $INBOX_DIR/description) is shown a link to the latest topics in search results and per-thread/per-message views. b) providing a link to contemporaries ("~YYYY-MM-DD") at around the thread overview skeleton area for per-thread and per-message views --- lib/PublicInbox/View.pm | 51 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) (limited to 'lib/PublicInbox/View.pm') diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index f23bfcc9..9c3ef104 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -7,8 +7,10 @@ package PublicInbox::View; use strict; use warnings; use bytes (); # only for bytes::length +use List::Util qw(max); use PublicInbox::MsgTime qw(msg_datestamp); -use PublicInbox::Hval qw(ascii_html obfuscate_addrs prurl mid_href); +use PublicInbox::Hval qw(ascii_html obfuscate_addrs prurl mid_href + ts2str fmt_ts); use PublicInbox::Linkify; use PublicInbox::MID qw(id_compress mids mids_for_index references $MID_EXTRACT); @@ -18,7 +20,6 @@ use PublicInbox::WwwStream qw(html_oneshot); use PublicInbox::Reply; use PublicInbox::ViewDiff qw(flush_diff); use PublicInbox::Eml; -use POSIX qw(strftime); use Time::Local qw(timegm); use PublicInbox::Smsg qw(subject_normalized); use constant COLS => 72; @@ -68,7 +69,13 @@ sub msg_page { my $over = $ctx->{over} = $ibx->over or return no_over_html($ctx); my ($id, $prev); my $next_arg = $ctx->{next_arg} = [ $ctx->{mid}, \$id, \$prev ]; - $ctx->{smsg} = $over->next_by_mid(@$next_arg) or return; # undef == 404 + + my $smsg = $ctx->{smsg} = $over->next_by_mid(@$next_arg) or + return; # undef == 404 + + # allow user to easily browse the range around this message if + # they have ->over + $ctx->{-t_max} = $smsg->{ts}; PublicInbox::WwwStream::aresponse($ctx, 200, \&msg_page_i); } @@ -168,9 +175,6 @@ sub nr_to_s ($$$) { $nr == 1 ? "$nr $singular" : "$nr $plural"; } -# human-friendly format -sub fmt_ts ($) { strftime('%Y-%m-%d %k:%M', gmtime($_[0])) } - # Displays the text of of the message for /$INBOX/$MSGID/[Tt]/ endpoint # this is already inside a
 sub eml_entry {
@@ -420,9 +424,20 @@ sub thread_html {
 	my $ibx = $ctx->{-inbox};
 	my ($nr, $msgs) = $ibx->over->get_thread($mid);
 	return missing_thread($ctx) if $nr == 0;
+
+	# link $INBOX_DIR/description text to "index_topics" view around
+	# the newest message in this thread
+	my $t = ts2str($ctx->{-t_max} = max(map { delete $_->{ts} } @$msgs));
+	my $t_fmt = fmt_ts($ctx->{-t_max});
+
 	my $skel = '
';
 	$skel .= $nr == 1 ? 'only message in thread' : 'end of thread';
-	$skel .= ", back to index\n\n";
+	$skel .= <~$t_fmt UTC | newest]
+
+EOF
 	$skel .= "Thread overview: ";
 	$skel .= $nr == 1 ? '(only message)' : "$nr+ messages";
 	$skel .= " (download: mbox.gz";
@@ -782,15 +797,22 @@ sub _parent_headers {
 	$rv;
 }
 
-# returns a string buffer via ->getline
+# returns a string buffer
 sub html_footer {
 	my ($ctx, $hdr) = @_;
 	my $ibx = $ctx->{-inbox};
 	my $upfx = '../';
-	my $skel = " index";
+	my $skel;
 	my $rv = '
';
 	if ($ibx->over) {
-		$skel .= "\n";
+		my $t = ts2str($ctx->{-t_max});
+		my $t_fmt = fmt_ts($ctx->{-t_max});
+		$skel .= <~$t_fmt UTC|newest]
+EOF
+
 		thread_skel(\$skel, $ctx, $hdr);
 		my ($next, $prev);
 		my $parent = '       ';
@@ -821,6 +843,8 @@ sub html_footer {
 			$parent = " parent";
 		}
 		$rv .= "$next $prev$parent ";
+	} else { # unindexed inboxes w/o over
+		$skel = qq( latest);
 	}
 	$rv .= qq(reply);
 	$rv .= $skel;
@@ -858,7 +882,7 @@ sub find_mid_root {
 	++$ctx->{root_idx} if $level == 0;
 	if ($node->{mid} eq $ctx->{mid}) {
 		$ctx->{found_mid_at} = $ctx->{root_idx};
-		return 0;
+		return 0; # stop iterating
 	}
 	1;
 }
@@ -1142,9 +1166,6 @@ sub dump_topics {
 	200;
 }
 
-# only for the t= query parameter passed to overview DB
-sub ts2str ($) { strftime('%Y%m%d%H%M%S', gmtime($_[0])) };
-
 sub str2ts ($) {
 	my ($yyyy, $mon, $dd, $hh, $mm, $ss) = unpack('A4A2A2A2A2A2', $_[0]);
 	timegm($ss || 0, $mm || 0, $hh || 0, $dd, $mon - 1, $yyyy);
@@ -1152,7 +1173,6 @@ sub str2ts ($) {
 
 sub pagination_footer ($$) {
 	my ($ctx, $latest) = @_;
-	delete $ctx->{qp} or return;
 	my $next = $ctx->{next_page} || '';
 	my $prev = $ctx->{prev_page} || '';
 	if ($prev) {
@@ -1204,6 +1224,7 @@ sub paginate_recent ($$) {
 	$msgs;
 }
 
+# GET /$INBOX - top-level inbox view for indexed inboxes
 sub index_topics {
 	my ($ctx) = @_;
 	my $msgs = paginate_recent($ctx, 200); # 200 is our window
-- 
cgit v1.2.3-24-ge0c7