user/dev discussion of public-inbox itself
 help / color / mirror / Atom feed
From: Eric Wong <e@yhbt.net>
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> (raw)
In-Reply-To: <20200827220500.27784-1-e@yhbt.net>

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. <b><a\nhref="$mid/">}.
@@ -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 <pre>
 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 = '<hr><pre>';
 	$skel .= $nr == 1 ? 'only message in thread' : 'end of thread';
-	$skel .= ", back to <a\nhref=\"../../\">index</a>\n\n";
+	$skel .= <<EOF;
+, other threads:[<a
+href="../../?t=$t">~$t_fmt UTC</a> | <a
+href="../../">newest</a>]
+
+EOF
 	$skel .= "<b\nid=t>Thread overview:</b> ";
 	$skel .= $nr == 1 ? '(only message)' : "$nr+ messages";
 	$skel .= " (download: <a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
@@ -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 = " <a\nhref=\"$upfx\">index</a>";
+	my $skel;
 	my $rv = '<pre>';
 	if ($ibx->over) {
-		$skel .= "\n";
+		my $t = ts2str($ctx->{-t_max});
+		my $t_fmt = fmt_ts($ctx->{-t_max});
+		$skel .= <<EOF;
+	other threads:[<a
+href="$upfx?t=$t">~$t_fmt UTC</a>|<a
+href="$upfx">newest</a>]
+EOF
+
 		thread_skel(\$skel, $ctx, $hdr);
 		my ($next, $prev);
 		my $parent = '       ';
@@ -821,6 +843,8 @@ sub html_footer {
 			$parent = " <a\nhref=\"$u\"\nrel=prev>parent</a>";
 		}
 		$rv .= "$next $prev$parent ";
+	} else { # unindexed inboxes w/o over
+		$skel = qq( <a\nhref="$upfx">latest</a>);
 	}
 	$rv .= qq(<a\nhref="#R">reply</a>);
 	$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 = "<b>$desc</b>";
+	if (my $t_max = $ctx->{-t_max}) {
+		$t_max = ts2str($t_max);
+		$top = qq(<a\nhref="$upfx?t=$t_max">$top</a>);
+	# we had some kind of query, link to /$INBOX/?t=YYYYMMDDhhmmss
+	} elsif ($ctx->{qp}->{t}) {
+		$top = qq(<a\nhref="./">$top</a>);
+	}
 	my $links = "<a\nhref=\"$help\">help</a> / ".
 			"<a\nhref=\"$color\">color</a> / ".
 			"<a\nhref=\"$atom\">Atom feed</a>";

  reply	other threads:[~2020-08-27 22:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-27 22:04 [PATCH 0/2] www: navigation tweaks Eric Wong
2020-08-27 22:04 ` Eric Wong [this message]
2020-08-27 22:50   ` [PATCH 1/2] www: improve navigation around comtemporary threads Kyle Meyer
2020-08-28  4:27     ` Eric Wong
2020-08-27 22:05 ` [PATCH 2/2] www: more descriptive pagination Eric Wong
2020-08-27 22:49 ` [PATCH 0/2] www: navigation tweaks Kyle Meyer

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=20200827220500.27784-2-e@yhbt.net \
    --to=e@yhbt.net \
    --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

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git