- delete $ctx->{qp} or return;
- my ($next, $prev);
- $next = $prev = ' ';
- my $latest = '';
-
- my $next_o = $ctx->{-next_o};
- if ($next_o) {
- $next = qq!<a\nhref="?o=$next_o"\nrel=next>next</a>!;
- }
- if (my $cur_o = $ctx->{-cur_o}) {
- $latest = qq! <a\nhref=.>latest</a>!;
-
- my $o = $cur_o - ($next_o - $cur_o);
- if ($o > 0) {
- $prev = qq!<a\nhref="?o=$o"\nrel=prev>prev</a>!;
- } elsif ($o == 0) {
- $prev = qq!<a\nhref=.\nrel=prev>prev</a>!;
+ pagination_footer($ctx, '.')
+}
+
+sub paginate_recent ($$) {
+ my ($ctx, $lim) = @_;
+ my $t = $ctx->{qp}->{t} || '';
+ my $opts = { limit => $lim };
+ my ($after, $before);
+
+ # Xapian uses '..' but '-' is perhaps friendier to URL linkifiers
+ # if only $after exists "YYYYMMDD.." because "." could be skipped
+ # if interpreted as an end-of-sentence
+ $t =~ s/\A([0-9]{8,14})-// and $after = str2ts($1);
+ $t =~ /\A([0-9]{8,14})\z/ and $before = str2ts($1);
+
+ my $ibx = $ctx->{-inbox};
+ my $msgs = $ibx->recent($opts, $after, $before);
+ my $nr = scalar @$msgs;
+ if ($nr < $lim && defined($after)) {
+ $after = $before = undef;
+ $msgs = $ibx->recent($opts);
+ $nr = scalar @$msgs;
+ }
+ my $more = $nr == $lim;
+ my ($newest, $oldest);
+ if ($nr) {
+ $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;