user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 10/18] view: /$INBOX/: show "messages from $old to $new"
Date: Mon, 29 Aug 2022 09:26:39 +0000	[thread overview]
Message-ID: <20220829092647.1512215-11-e@80x24.org> (raw)
In-Reply-To: <20220829092647.1512215-1-e@80x24.org>

With the ViewVCS commit view using /$INBOX/?t=YYYYMMDDhhmmss-
links, the use of `t=' may not be immediately obvious to a
reader and confuse them into thinking the inbox hasn't been
updated in a while.

So add a header to the top of the page whenever the `t=' query
parameter is used.

And kill a couple of redundant variable assignments while we're
at it.
---
 lib/PublicInbox/View.pm | 35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 466ec6cf..11ed2d76 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -20,6 +20,7 @@ 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 PublicInbox::ContentHash qw(content_hash);
@@ -1161,9 +1162,10 @@ sub dump_topics {
 	}
 
 	my @out;
-	my $ibx = $ctx->{ibx};
-	my $obfs_ibx = $ibx->{obfuscate} ? $ibx : undef;
-
+	my $obfs_ibx = $ctx->{ibx}->{obfuscate} ? $ctx->{ibx} : undef;
+	if (my $note = delete $ctx->{t_note}) {
+		push @out, $note; # "messages from ... to ..."
+	}
 	# sort by recency, this allows new posts to "bump" old topics...
 	foreach my $topic (sort { $b->[0] <=> $a->[0] } @$order) {
 		my ($ds, $n, $seen, $top_subj, @extra) = @$topic;
@@ -1222,7 +1224,7 @@ sub pagination_footer ($$) {
 		$next = $next ? "$next | " : '             | ';
 		$prev .= qq[ | <a\nhref="$latest">latest</a>];
 	}
-	($next || $prev) ? "<hr><pre>page: $next$prev</pre>" : '';
+	($next || $prev) ? "<hr><pre id=nav>page: $next$prev</pre>" : '';
 }
 
 sub paginate_recent ($$) {
@@ -1238,21 +1240,29 @@ sub paginate_recent ($$) {
 	$t =~ /\A([0-9]{8,14})\z/ and $before = str2ts($1);
 
 	my $msgs = $ctx->{ibx}->over->recent($opts, $after, $before);
-	my $nr = scalar @$msgs;
-	if ($nr < $lim && defined($after)) {
+	if (defined($after) && scalar(@$msgs) < $lim) {
 		$after = $before = undef;
 		$msgs = $ctx->{ibx}->over->recent($opts);
-		$nr = scalar @$msgs;
 	}
-	my $more = $nr == $lim;
+	my $more = scalar(@$msgs) == $lim;
 	my ($newest, $oldest);
-	if ($nr) {
+	if (@$msgs) {
 		$newest = $msgs->[0]->{ts};
 		$oldest = $msgs->[-1]->{ts};
 		# if we only had $after, our SQL query in ->recent ordered
 		if ($newest < $oldest) {
 			($oldest, $newest) = ($newest, $oldest);
-			$more = 0 if defined($after) && $after < $oldest;
+			$more = undef if defined($after) && $after < $oldest;
+		}
+		if (defined($after // $before)) {
+			my $n = strftime('%Y-%m-%d %H:%M:%S', gmtime($newest));
+			my $o = strftime('%Y-%m-%d %H:%M:%S', gmtime($oldest));
+			$ctx->{t_note} = <<EOM;
+ messages from $o to $n UTC, [<a href="#nav">more...</a>]
+EOM
+			my $s = ts2str($newest);
+			$ctx->{prev_page} = qq[<a\nhref="?t=$s-"\nrel=prev>] .
+						'prev (newer)</a>';
 		}
 	}
 	if (defined($oldest) && $more) {
@@ -1260,11 +1270,6 @@ sub paginate_recent ($$) {
 		$ctx->{next_page} = qq[<a\nhref="?t=$s"\nrel=next>] .
 					'next (older)</a>';
 	}
-	if (defined($newest) && (defined($before) || defined($after))) {
-		my $s = ts2str($newest);
-		$ctx->{prev_page} = qq[<a\nhref="?t=$s-"\nrel=prev>] .
-					'prev (newer)</a>';
-	}
 	$msgs;
 }
 

  parent reply	other threads:[~2022-08-29  9:26 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-29  9:26 [PATCH 00/18] WWW: patch, tree, git glossary Eric Wong
2022-08-29  9:26 ` [PATCH 01/18] solver: create tmpdir lazily Eric Wong
2022-08-29  9:26 ` [PATCH 02/18] viewvcs: share File::Temp::Dir with solver Eric Wong
2022-08-29  9:26 ` [PATCH 03/18] viewvcs: delay stringification of solver debug log Eric Wong
2022-08-29  9:26 ` [PATCH 04/18] www: allow html_oneshot to take an array arg Eric Wong
2022-08-29  9:26 ` [PATCH 05/18] viewvcs: use array for highlighted blob display Eric Wong
2022-08-29  9:26 ` [PATCH 06/18] viewvcs: add patch download link for single-parent commits Eric Wong
2022-08-29  9:26 ` [PATCH 07/18] viewvcs: author date links to contemporary messages Eric Wong
2022-08-29  9:26 ` [PATCH 08/18] view: speed up /$INBOX/ landing page by 0.5-1.0% Eric Wong
2022-08-29  9:26 ` [PATCH 09/18] treewide: ditch inbox->recent method Eric Wong
2022-08-29  9:26 ` Eric Wong [this message]
2022-08-29  9:26 ` [PATCH 11/18] view: cleanups and reuse for {obuf} preparation Eric Wong
2022-08-29  9:26 ` [PATCH 12/18] www: atom: fix "changed" href to nowhere Eric Wong
2022-08-29  9:26 ` [PATCH 13/18] www: provide text/help/#search anchor Eric Wong
2022-08-29  9:26 ` [PATCH 14/18] solver: early make hints detection more robust Eric Wong
2022-08-29  9:26 ` [PATCH 15/18] viewvcs: add tree view Eric Wong
2022-08-29  9:26 ` [PATCH 16/18] viewvcs: reduce hash assignments for commit info Eric Wong
2022-08-29  9:26 ` [PATCH 17/18] viewvcs: add glossary for commit Eric Wong
2022-08-29  9:57   ` [19/18 PATCH] viewvcs: fixup commit glossary stuff Eric Wong
2022-08-29  9:26 ` [PATCH 18/18] viewvcs: show "blob $OID" rather than "$OID blob" Eric Wong

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=20220829092647.1512215-11-e@80x24.org \
    --to=e@80x24.org \
    --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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).