From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C0D1E1F66F for ; Thu, 27 Aug 2020 22:05:00 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/2] www: improve navigation around comtemporary threads Date: Thu, 27 Aug 2020 22:04:59 +0000 Message-Id: <20200827220500.27784-2-e@yhbt.net> In-Reply-To: <20200827220500.27784-1-e@yhbt.net> References: <20200827220500.27784-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 navigatin 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 --- Documentation/mknews.perl | 3 ++- lib/PublicInbox/Hval.pm | 9 ++++++- lib/PublicInbox/Over.pm | 2 +- lib/PublicInbox/SearchView.pm | 11 ++++++-- lib/PublicInbox/Smsg.pm | 2 +- lib/PublicInbox/View.pm | 51 ++++++++++++++++++++++++----------- lib/PublicInbox/WwwListing.pm | 4 +-- lib/PublicInbox/WwwStream.pm | 9 ++++++- 8 files changed, 67 insertions(+), 24 deletions(-) diff --git a/Documentation/mknews.perl b/Documentation/mknews.perl index f053e2bf..510a4e18 100755 --- a/Documentation/mknews.perl +++ b/Documentation/mknews.perl @@ -7,6 +7,7 @@ use strict; use PublicInbox::Eml; use PublicInbox::View; +use PublicInbox::Hval qw(fmt_ts); use PublicInbox::MsgTime qw(msg_datestamp); use PublicInbox::MID qw(mids mid_escape); END { $INC{'Plack/Util.pm'} and warn "$0 should not have loaded Plack::Util\n" } @@ -91,7 +92,7 @@ sub mime2txt { my $title = $mime->header('Subject'); $title =~ s/^\s*\[\w+\]\s*//g; # [ANNOUNCE] or [ANN] my $dtime = msg_datestamp($mime->header_obj); - $title .= ' - ' . PublicInbox::View::fmt_ts($dtime) . ' UTC'; + $title .= ' - ' . fmt_ts($dtime) . ' UTC'; print $out $title, "\n" or die; my $uline = '=' x length($title); print $out $uline, "\n\n" or die; diff --git a/lib/PublicInbox/Hval.pm b/lib/PublicInbox/Hval.pm index e21a64a6..fb21041a 100644 --- a/lib/PublicInbox/Hval.pm +++ b/lib/PublicInbox/Hval.pm @@ -10,7 +10,8 @@ use Encode qw(find_encoding); use PublicInbox::MID qw/mid_clean mid_escape/; use base qw/Exporter/; our @EXPORT_OK = qw/ascii_html obfuscate_addrs to_filename src_escape - to_attr prurl mid_href/; + to_attr prurl mid_href fmt_ts ts2str/; +use POSIX qw(strftime); my $enc_ascii = find_encoding('us-ascii'); # safe-ish acceptable filename pattern for portability @@ -123,4 +124,10 @@ sub to_attr ($) { $first . $str; } +# for the t= query parameter passed to overview DB +sub ts2str ($) { strftime('%Y%m%d%H%M%S', gmtime($_[0])) }; + +# human-friendly format +sub fmt_ts ($) { strftime('%Y-%m-%d %k:%M', gmtime($_[0])) } + 1; diff --git a/lib/PublicInbox/Over.pm b/lib/PublicInbox/Over.pm index 0957cbdd..08112386 100644 --- a/lib/PublicInbox/Over.pm +++ b/lib/PublicInbox/Over.pm @@ -126,7 +126,7 @@ sub get_all { my $nr = scalar(@_) or return []; my $in = '?' . (',?' x ($nr - 1)); do_get($self, <<"", { cull => 1, limit => $nr }, @_); -SELECT num,ds,ddd FROM over WHERE num IN ($in) +SELECT num,ts,ds,ddd FROM over WHERE num IN ($in) } diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm index 76428dfb..7521a66d 100644 --- a/lib/PublicInbox/SearchView.pm +++ b/lib/PublicInbox/SearchView.pm @@ -5,9 +5,10 @@ package PublicInbox::SearchView; use strict; use v5.10.1; +use List::Util qw(max); use URI::Escape qw(uri_unescape); use PublicInbox::Smsg; -use PublicInbox::Hval qw(ascii_html obfuscate_addrs mid_href); +use PublicInbox::Hval qw(ascii_html obfuscate_addrs mid_href fmt_ts); use PublicInbox::View; use PublicInbox::WwwAtomStream; use PublicInbox::WwwStream qw(html_oneshot); @@ -109,13 +110,15 @@ sub mset_summary { }; next; }; + $ctx->{-t_max} //= $smsg->{ts}; + my $s = ascii_html($smsg->{subject}); my $f = ascii_html($smsg->{from_name}); if ($obfs_ibx) { obfuscate_addrs($obfs_ibx, $s); obfuscate_addrs($obfs_ibx, $f); } - my $date = PublicInbox::View::fmt_ts($smsg->{ds}); + my $date = fmt_ts($smsg->{ds}); my $mid = mid_href($smsg->{mid}); $s = '(no subject)' if $s eq ''; $$res .= qq{$rank. }. @@ -295,6 +298,10 @@ sub mset_thread { PublicInbox::View::walk_thread($rootset, $ctx, \&PublicInbox::View::pre_thread); + # link $INBOX_DIR/description text to "recent" view around + # the newest message in this result set: + $ctx->{-t_max} = max(map { delete $_->{ts} } @$msgs); + @$msgs = reverse @$msgs if $r; $ctx->{msgs} = $msgs; PublicInbox::WwwStream::aresponse($ctx, 200, \&mset_thread_i); diff --git a/lib/PublicInbox/Smsg.pm b/lib/PublicInbox/Smsg.pm index 0a0384ef..171e0a00 100644 --- a/lib/PublicInbox/Smsg.pm +++ b/lib/PublicInbox/Smsg.pm @@ -83,7 +83,7 @@ sub psgi_cull ($) { # drop NNTP-only fields which aren't relevant to PSGI results: # saves ~80K on a 200 item search result: # TODO: we may need to keep some of these for JMAP... - delete @$self{qw(ts tid to cc bytes lines)}; + delete @$self{qw(tid to cc bytes lines)}; $self; } 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
diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm
index 0af0fe68..365743cf 100644
--- a/lib/PublicInbox/WwwListing.pm
+++ b/lib/PublicInbox/WwwListing.pm
@@ -6,7 +6,7 @@
 package PublicInbox::WwwListing;
 use strict;
 use warnings;
-use PublicInbox::Hval qw(ascii_html prurl);
+use PublicInbox::Hval qw(ascii_html prurl fmt_ts);
 use PublicInbox::Linkify;
 use PublicInbox::View;
 use PublicInbox::Inbox;
@@ -91,7 +91,7 @@ sub new {
 
 sub ibx_entry {
 	my ($mtime, $ibx, $env) = @_;
-	my $ts = PublicInbox::View::fmt_ts($mtime);
+	my $ts = fmt_ts($mtime);
 	my $url = prurl($env, $ibx->{url});
 	my $tmp = <<"";
 * $ts - $url
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index d79770ed..e06e3456 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -10,7 +10,7 @@ use strict;
 use parent qw(Exporter PublicInbox::GzipFilter);
 our @EXPORT_OK = qw(html_oneshot);
 use bytes (); # length
-use PublicInbox::Hval qw(ascii_html prurl);
+use PublicInbox::Hval qw(ascii_html prurl ts2str);
 our $TOR_URL = 'https://www.torproject.org/';
 our $CODE_URL = 'https://public-inbox.org/public-inbox.git';
 
@@ -43,6 +43,13 @@ sub html_top ($) {
 	my $color = $upfx.'_/text/color';
 	my $atom = $ctx->{-atom} || $upfx.'new.atom';
 	my $top = "$desc";
+	if (my $t_max = $ctx->{-t_max}) {
+		$t_max = ts2str($t_max);
+		$top = qq($top);
+	# we had some kind of query, link to /$INBOX/?t=YYYYMMDDhhmmss
+	} elsif ($ctx->{qp}->{t}) {
+		$top = qq($top);
+	}
 	my $links = "help / ".
 			"color / ".
 			"Atom feed";