]> Sergey Matveev's repositories - public-inbox.git/commitdiff
www: improve navigation around contemporary threads
authorEric Wong <e@yhbt.net>
Thu, 27 Aug 2020 22:04:59 +0000 (22:04 +0000)
committerEric Wong <e@yhbt.net>
Fri, 28 Aug 2020 04:25:15 +0000 (04:25 +0000)
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

Documentation/mknews.perl
lib/PublicInbox/Hval.pm
lib/PublicInbox/Over.pm
lib/PublicInbox/SearchView.pm
lib/PublicInbox/Smsg.pm
lib/PublicInbox/View.pm
lib/PublicInbox/WwwListing.pm
lib/PublicInbox/WwwStream.pm

index f053e2bfb9e558541778762a4d6b3b79bd0b633d..510a4e1810558e5a74efdbdd4386bdb81b00644c 100755 (executable)
@@ -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;
index e21a64a60e6690636555c2d7dc52473301ba5d25..fb21041acafcaa534c3563a1f191f902acc631df 100644 (file)
@@ -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;
index 0957cbdd78cca6290832f93e25b7203977904456..081123868795fd9b22997488331b0bc39dc51800 100644 (file)
@@ -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)
 
 }
 
index 76428dfbdbc455127161fbc8f76df67c5e7e6308..7521a66ddb82c51bc2a6b9b7b1b77772403d2531 100644 (file)
@@ -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);
index 0a0384efaadf7811d372631885ec771345370c7b..171e0a00908e4b7bdf51ba05beda6dcc498aa08c 100644 (file)
@@ -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;
 }
 
index f23bfcc921563006198ba3a0f33ac8f687745af0..9c3ef104f1a83ab28edfce75cf2ce2308ad3af76 100644 (file)
@@ -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
index 0af0fe68cd7dea676abeec809b23bb3eb1c496d2..365743cfdf90d13bc4b56b95297dc1d04e93f716 100644 (file)
@@ -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
index d79770ed1d82b8dbd484ca84dbf445962116bef8..e06e3456ae19cbf163fcae457cce533f58bf33c0 100644 (file)
@@ -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>";