From 16a561346db4b158682abab7889050bac4e38fe1 Mon Sep 17 00:00:00 2001 From: swaggboi Date: Sat, 28 Oct 2023 11:34:44 -0400 Subject: [PATCH] Do max_pages for threads --- README.md | 2 +- example_post_text.conf | 1 + lib/PostText.pm | 4 ++++ lib/PostText/Model/Thread.pm | 8 ++++++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 13efa40..94b8df9 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ tests locally: ## TODOs -1. Hide ancient posts +1. Hide ancient posts (test this, dev DB is broken fuck) 1. Put a link to search_page somewhere 1. "All new posts flagged" mode (require approval for new posts) 1. Tests for mod-only user? diff --git a/example_post_text.conf b/example_post_text.conf index d410840..7926ff1 100644 --- a/example_post_text.conf +++ b/example_post_text.conf @@ -1,4 +1,5 @@ { + max_thread_pages => 10, threads_per_page => 5, remarks_per_page => 5, results_per_page => 5, diff --git a/lib/PostText.pm b/lib/PostText.pm index 1caa0a4..abfc485 100644 --- a/lib/PostText.pm +++ b/lib/PostText.pm @@ -104,6 +104,10 @@ sub startup($self) { $self->page->per_page($results_per_page) } + if (my $max_thread_pages = $self->config->{'max_thread_pages'}) { + $self->thread->max_pages($max_thread_pages) + } + $self->asset->process; push @{$self->commands->namespaces}, 'PostText::Command'; diff --git a/lib/PostText/Model/Thread.pm b/lib/PostText/Model/Thread.pm index 9564910..01ec23b 100644 --- a/lib/PostText/Model/Thread.pm +++ b/lib/PostText/Model/Thread.pm @@ -2,7 +2,7 @@ package PostText::Model::Thread; use Mojo::Base -base, -signatures; -has [qw{pg hr}]; +has [qw{pg hr max_pages}]; has per_page => 5; @@ -57,7 +57,11 @@ sub last_page($self) { # Add a page for 'remainder' posts $last_page++ if $thread_count % $self->per_page; - $last_page; + if ($max_pages) { + $last_page = $max_pages if $last_page > $max_pages + } + + return $last_page; } sub count($self) {