diff options
Diffstat (limited to 'lib/VNWeb/Discussions/Thread.pm')
-rw-r--r-- | lib/VNWeb/Discussions/Thread.pm | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/lib/VNWeb/Discussions/Thread.pm b/lib/VNWeb/Discussions/Thread.pm index 3fd67dbe..b3820dd7 100644 --- a/lib/VNWeb/Discussions/Thread.pm +++ b/lib/VNWeb/Discussions/Thread.pm @@ -43,34 +43,36 @@ elm_api DiscussionsPoll => $POLL_OUT, $POLL_IN, sub { -my $REPLY = { +my $REPLY = form_compile any => { tid => { vndbid => 't' }, - old => { _when => 'out', anybool => 1 }, - msg => { _when => 'in', maxlength => 32768 } + old => { anybool => 1 }, + msg => { maxlength => 32768 } }; -my $REPLY_IN = form_compile in => $REPLY; -my $REPLY_OUT = form_compile out => $REPLY; - -elm_api DiscussionsReply => $REPLY_OUT, $REPLY_IN, sub { +js_api DiscussionReply => $REPLY, sub { my($data) = @_; my $t = tuwf->dbRowi('SELECT id, locked FROM threads t WHERE id =', \$data->{tid}, 'AND', sql_visible_threads()); return tuwf->resNotFound if !$t->{id}; - return elm_Unauth if !can_edit t => $t; + return tuwf->resDenied if !can_edit t => $t; my $num = sql '(SELECT MAX(num)+1 FROM threads_posts WHERE tid =', \$data->{tid}, ')'; my $msg = bb_subst_links $data->{msg}; $num = tuwf->dbVali('INSERT INTO threads_posts', { tid => $t->{id}, num => $num, uid => auth->uid, msg => $msg }, 'RETURNING num'); - elm_Redirect "/$t->{id}.$num#last"; + +{ _redir => "/$t->{id}.$num#last" }; }; sub metabox_ { - my($t) = @_; - div_ class => 'mainbox', sub { + my($t, $posts) = @_; + article_ sub { h1_ sub { lit_ bb_format $t->{title}, idonly => 1 }; + # UGLY hack: private threads from Multi (u1) are sometimes (ab)used for system notifications, treat that case differently. + if ($t->{private} && $posts->[0]{user_id} && $posts->[0]{user_id} eq 'u1') { + h2_ 'System notification'; + return; + } h2_ 'Hidden' if $t->{hidden}; h2_ 'Private' if $t->{private}; h2_ 'Locked' if $t->{locked}; @@ -80,12 +82,12 @@ sub metabox_ { a_ href => "/t/$_->{btype}", $BOARD_TYPE{$_->{btype}}{txt}; if($_->{iid}) { txt_ ' > '; - a_ style => 'font-weight: bold', href => "/t/$_->{btype}$_->{iid}", "$_->{btype}$_->{iid}"; + a_ style => 'font-weight: bold', href => "/t/$_->{iid}", $_->{iid}; txt_ ':'; if($_->{title}) { - a_ href => "/$_->{btype}$_->{iid}", title => $_->{original}||$_->{title}, $_->{title}; + a_ href => "/$_->{iid}", tattr $_; } else { - b_ '[deleted]'; + strong_ '[deleted]'; } } } for $t->{boards}->@*; @@ -100,12 +102,12 @@ sub posts_ { my sub url { "/$t->{id}".($_?"/$_":'') } paginate_ \&url, $page, [ $t->{count}, 25 ], 't'; - div_ class => 'mainbox thread', id => 'threadstart', sub { + article_ class => 'thread', id => 'threadstart', sub { table_ class => 'stripe', sub { - tr_ mkclass(deleted => $_->{hidden}), id => $_->{num}, sub { + tr_ mkclass(deleted => defined $_->{hidden}), id => "p$_->{num}", sub { td_ class => 'tc1', $_ == $posts->[$#$posts] ? (id => 'last') : (), sub { a_ href => "/$t->{id}.$_->{num}", "#$_->{num}"; - if(!$_->{hidden} || auth->permBoard) { + if(!defined $_->{hidden} || auth->permBoard) { txt_ ' by '; user_ $_; br_; @@ -113,7 +115,7 @@ sub posts_ { } }; td_ class => 'tc2', sub { - i_ class => 'edit', sub { + small_ class => 'edit', sub { txt_ '< '; if(can_edit t => $_) { a_ href => "/$t->{id}.$_->{num}/edit", 'edit'; @@ -121,12 +123,15 @@ sub posts_ { } a_ href => "/report/$t->{id}.$_->{num}", 'report'; txt_ ' >'; - }; - if($_->{hidden}) { - i_ class => 'deleted', 'Post deleted.'; + } if !defined $_->{hidden} || can_edit t => $_; + if(defined $_->{hidden}) { + small_ sub { + txt_ 'Post deleted'; + lit_ length $_->{hidden} ? ': '.bb_format $_->{hidden}, inline => 1 : '.'; + }; } else { lit_ bb_format $_->{msg}; - i_ class => 'lastmod', 'Last modified on '.fmtdate($_->{edited}, 'full') if $_->{edited}; + small_ class => 'lastmod', 'Last modified on '.fmtdate($_->{edited}, 'full') if $_->{edited}; } }; } for @$posts; @@ -140,9 +145,9 @@ sub reply_ { my($t, $posts, $page) = @_; return if $t->{count} > $page*25; if(can_edit t => $t) { - elm_ 'Discussions.Reply' => $REPLY_OUT, { tid => $t->{id}, old => $posts->[$#$posts]{date} < time-182*24*3600 }; + div_ widget(DiscussionReply => $REPLY, { tid => $t->{id}, old => $posts->[$#$posts]{date} < time-182*24*3600 }), ''; } else { - div_ class => 'mainbox', sub { + article_ sub { h1_ 'Reply'; p_ class => 'center', !auth ? 'You must be logged in to reply to this thread.' : @@ -189,16 +194,14 @@ TUWF::get qr{/$RE{tid}(?:(?<sep>[\./])$RE{num})?}, sub { LEFT JOIN users u ON tpv.uid = u.id AND NOT u.ign_votes LEFT JOIN threads_poll_votes tpm ON tpm.optid = tpo.id AND tpm.uid =', \auth->uid, ' WHERE tpo.tid =', \$id, ' - GROUP BY tpo.id, tpo.option, tpm.optid' + GROUP BY tpo.id, tpo.option, tpm.optid + ORDER BY tpo.id' ); - # Mark a notification for this thread as read, if there is one. - tuwf->dbExeci( - 'UPDATE notifications SET read = NOW() WHERE uid =', \auth->uid, 'AND iid =', \$id, 'AND read IS NULL' - ) if auth && $t->{count} <= $page*25; + auth->notiRead($id, [ map $_->{num}, $posts->@* ]) if @$posts; - framework_ title => $t->{title}, $num ? (js => 1, pagevars => {sethash=>$num}) : (), sub { - metabox_ $t; + framework_ title => $t->{title}, dbobj => $t, $num ? (js => 1, pagevars => {sethash=>"p$num"}) : (), sub { + metabox_ $t, $posts; elm_ 'Discussions.Poll' => $POLL_OUT, { question => $t->{poll_question}, max_options => $t->{poll_max_options}, |