X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FForum.pm;h=0a27acc7547ae88e11d29a4d8685e939e70f447e;hb=16fbe66ea19aa3882114267808963281cf7d37ad;hp=d242ed99e9a1cb2fbf30e7580371e0dc49cef567;hpb=ffd7bf407e56bf271981151b6845f26ff1b366bc;p=ndwebbie.git diff --git a/lib/NDWeb/Controller/Forum.pm b/lib/NDWeb/Controller/Forum.pm index d242ed9..0a27acc 100644 --- a/lib/NDWeb/Controller/Forum.pm +++ b/lib/NDWeb/Controller/Forum.pm @@ -208,7 +208,13 @@ sub thread : Local { my $dbh = $c->model; $c->forward('findThread'); - $thread = $c->stash->{thread}; + $c->forward('findPosts') if $c->stash->{thread}; + $c->forward('markThreadAsRead') if $c->user_exists; +} + +sub findPosts :Private { + my ( $self, $c, $thread ) = @_; + my $dbh = $c->model; my $posts = $dbh->prepare(q{ SELECT u.username,date_trunc('seconds',fp.time::timestamp) AS time @@ -221,7 +227,7 @@ sub thread : Local { WHERE ft.ftid = $1 ORDER BY fp.time ASC }); - $posts->execute($c->stash->{thread}->{ftid},$c->stash->{UID}); + $posts->execute($thread,$c->stash->{UID}); my @posts; while (my $post = $posts->fetchrow_hashref){ @@ -230,7 +236,6 @@ sub thread : Local { } $c->stash(posts => \@posts); - $c->forward('markThreadAsRead') if $c->user_exists; } @@ -314,7 +319,6 @@ sub moveThreads : Local { sub newThread : Local { my ( $self, $c, $board ) = @_; - my $dbh = $c->model; $c->forward('findBoard'); $board = $c->stash->{board}; @@ -322,16 +326,21 @@ sub newThread : Local { unless ($c->stash->{board}->{post}){ $c->acl_access_denied('test',$c->action,'No post access to board.') } - + + $c->forward('insertThread'); + $c->forward('addPost',[$c->stash->{thread}]); +} + +sub insertThread : Private { + my ( $self, $c, $board ) = @_; + my $dbh = $c->model; + my $insert = $dbh->prepare(q{INSERT INTO forum_threads (ftid,fbid,subject,uid) VALUES(DEFAULT,$1,$2,$3) RETURNING (ftid); }); - - $insert->execute($board->{fbid},html_escape($c->req->param('subject')),$c->stash->{UID}); - my $thread = $insert->fetchrow; + $insert->execute($board,html_escape($c->req->param('subject')),$c->stash->{UID}); + $c->stash(thread => $insert->fetchrow); $insert->finish; - $c->forward('addPost',[$thread]); - } sub addPost : Local {