- push @recent, $cur if $cur;
- @recent = map { $_->[1] } sort { $b->[0] <=> $a->[0] } @recent;
- $fh->write(join('', @recent) . '</pre>');
-}
-
-sub emit_index_topics {
- my ($state) = @_;
- my ($off) = (($state->{ctx}->{cgi}->param('o') || '0') =~ /(\d+)/);
- $state->{order} = [];
- $state->{subjs} = {};
- $state->{latest} = {};
- my $max = 25;
- my %opts = ( offset => $off, limit => $max * 4 );
- while (scalar @{$state->{order}} < $max) {
- my $sres = $state->{srch}->query('', \%opts);
- my $nr = scalar @{$sres->{msgs}} or last;
-
- for (thread_results(load_results($sres))->rootset) {
- add_topic($state, $_, 0);
+ $ctx->{-html_tip} = '<pre>' . join("\n", @out) . '</pre>';
+ 200;
+}
+
+sub ts2str ($) {
+ my ($ts) = @_;
+ POSIX::strftime('%Y%m%d%H%M%S', gmtime($ts));
+}
+
+sub str2ts ($) {
+ my ($yyyy, $mon, $dd, $hh, $mm, $ss) = unpack('A4A2A2A2A2A2', $_[0]);
+ timegm($ss, $mm, $hh, $dd, $mon - 1, $yyyy);
+}
+
+sub pagination_footer ($$) {
+ my ($ctx, $latest) = @_;
+ delete $ctx->{qp} or return;
+ my $next = $ctx->{next_page} || '';
+ my $prev = $ctx->{prev_page} || '';
+ if ($prev) {
+ $next = $next ? "$next " : ' ';
+ $prev .= qq! <a\nhref='$latest'>latest</a>!;
+ }
+ "<hr><pre>page: $next$prev</pre>";
+}
+
+sub index_nav { # callback for WwwStream
+ my (undef, $ctx) = @_;
+ pagination_footer($ctx, '.')
+}
+
+sub paginate_recent ($) {
+ my ($ctx) = @_;
+ my $t = $ctx->{qp}->{t} || '';
+ my $lim = 200; # this is our window
+ 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(\d{8,14})-// and $after = str2ts($1);
+ $t =~ /\A(\d{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;