diff --git a/lib/PostText/Controller/Thread.pm b/lib/PostText/Controller/Thread.pm index f1ae968..aa87afd 100644 --- a/lib/PostText/Controller/Thread.pm +++ b/lib/PostText/Controller/Thread.pm @@ -51,32 +51,21 @@ sub by_id($self) { $last_page = $self->remark->last_page_for($thread_id); $remarks = $self->remark->by_page_for($thread_id, $this_page); - if (my $thread_body = $thread->{'body'}) { - $self->stash( - thread => $thread, - base_path => $base_path, - this_page => $this_page, - last_page => $last_page, - remarks => $remarks - ) - } - else { - $self->stash( - thread => {}, - remarks => [], - status => 404, - error => 'Thread not found 🤷' - ) - } + $self->stash( + thread => $thread, + base_path => $base_path, + this_page => $this_page, + last_page => $last_page, + remarks => $remarks + ); + + $self->stash(status => 404, error => 'Thread not found 🤷') + unless keys %{$thread}; # Check for remarks or thread page number to make sure # remark->by_page_for did its job - unless ((my $first_remark = $remarks->[0]) || 1 >= $this_page) { - $self->stash( - status => 404, - error => 'Page not found 🕵️' - ) - } + $self->stash(status => 404, error => 'Page not found 🕵️') + unless 1 >= $this_page || scalar @{$remarks}; $self->render; } diff --git a/templates/thread/by_id.html.ep b/templates/thread/by_id.html.ep index cdbf912..73e8f42 100644 --- a/templates/thread/by_id.html.ep +++ b/templates/thread/by_id.html.ep @@ -1,12 +1,12 @@ % layout 'default'; % title my $thread_id = $thread->{'id'} ? "Thread #$thread_id" : '?';

<%= title %>

-<% if (my $thread_id = $thread->{'id'}) { =%> +<% if (keys %{$thread}) { =%>

<%= $thread->{'title'} %> - #<%= $thread_id %> + #<%= $thread->{'id'} %>

@@ -38,7 +38,7 @@
<% } =%> -<% if (my $first_remark = $remarks->[0]) { =%> +<% if (scalar @{$remarks}) { =%>

Remarks

<% for my $remark (@{$remarks}) { =%>