about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/Hval.pm9
-rw-r--r--lib/PublicInbox/Over.pm2
-rw-r--r--lib/PublicInbox/SearchView.pm11
-rw-r--r--lib/PublicInbox/Smsg.pm2
-rw-r--r--lib/PublicInbox/View.pm51
-rw-r--r--lib/PublicInbox/WwwListing.pm4
-rw-r--r--lib/PublicInbox/WwwStream.pm9
7 files changed, 65 insertions, 23 deletions
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>";