[dw-free] Also count screened comments
[commit: http://hg.dwscoalition.org/dw-free/rev/a7ecd3b0754f]
http://bugs.dwscoalition.org/show_bug.cgi?id=2827
Display number of comments as ( $x visible | $y screened comments ) when the
entry has screened comments and the viewer is allowed to manage these
comments.
Patch by
yvi.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=2827
Display number of comments as ( $x visible | $y screened comments ) when the
entry has screened comments and the viewer is allowed to manage these
comments.
Patch by
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
Files modified:
- bin/upgrading/en.dat
- cgi-bin/LJ/Entry.pm
- cgi-bin/LJ/Talk.pm
- htdocs/talkpost.bml
- htdocs/talkread.bml
-------------------------------------------------------------------------------- diff -r 032324f7aa40 -r a7ecd3b0754f bin/upgrading/en.dat --- a/bin/upgrading/en.dat Wed Feb 08 16:44:08 2012 +0800 +++ b/bin/upgrading/en.dat Thu Feb 09 19:41:01 2012 +0800 @@ -3833,12 +3833,16 @@ talk.comments.counted=[[replycount]] [[?replycount|comment|comments]] +talk.comments.counted.screened=[[replycount]] visible | [[screenedcount]] screened [[?screenedcount|comment|comments]] + talk.comments.disabled_maintainer=Comments disabled by a maintainer of this community talk.commentsread=Read comments talk.commentsread.counted=Read [[replycount]] [[?replycount|comment|comments]] +talk.commentsread.counted.screened=Read [[replycount]] visible | [[screenedcount]] screened [[?screenedcount|comment|comments]] + talk.commentsread.nocomments=No comments talk.curname_Groups=<strong>Filters:</strong> diff -r 032324f7aa40 -r a7ecd3b0754f cgi-bin/LJ/Entry.pm --- a/cgi-bin/LJ/Entry.pm Wed Feb 08 16:44:08 2012 +0800 +++ b/cgi-bin/LJ/Entry.pm Thu Feb 09 19:41:01 2012 +0800 @@ -1935,6 +1935,7 @@ $sclient->insert_jobs( @jobs ) if @jobs; $u->memc_delete( 'activeentries' ); + LJ::MemCache::delete( [ $jid, "screenedcount:$jid:$nodeid" ] ); return $num; } diff -r 032324f7aa40 -r a7ecd3b0754f cgi-bin/LJ/Talk.pm --- a/cgi-bin/LJ/Talk.pm Wed Feb 08 16:44:08 2012 +0800 +++ b/cgi-bin/LJ/Talk.pm Thu Feb 09 19:41:01 2012 +0800 @@ -624,6 +624,8 @@ LJ::set_logprop($u, $itemid, { 'hasscreened' => 1 }); } + LJ::MemCache::delete( [ $userid, "screenedcount:$userid:$itemid" ] ); + LJ::Talk::update_commentalter($u, $itemid); return; } @@ -658,6 +660,8 @@ LJ::set_logprop($u, $itemid, { 'hasscreened' => 0 }) unless $hasscreened; } + LJ::MemCache::delete( [ $userid, "screenedcount:$userid:$itemid" ] ); + LJ::Talk::update_commentalter($u, $itemid); return; } @@ -2559,6 +2563,27 @@ return $count; } +# get the total amount of screened comments on the given journal entry +sub get_screenedcount { + my ( $ju, $jitemid ) = @_; + $jitemid += 0; + return undef unless $ju && $jitemid; + + my $memkey = [$ju->{userid}, "screenedcount:$ju->{userid}:$jitemid", 60*30]; + my $count = LJ::MemCache::get( $memkey ); + return $count if $count; + + my $dbcr = LJ::get_cluster_def_reader( $ju ); + return unless $dbcr; + + $count = $dbcr->selectrow_array("SELECT COUNT(jtalkid) FROM talk2 WHERE " . + "journalid=? AND nodeid=? AND state='S'", undef, + $ju->{userid}, $jitemid); + LJ::MemCache::add($memkey, $count); + return $count; +} + + sub comment_htmlid { my $id = shift or return ''; return "cmt$id"; @@ -3055,6 +3080,8 @@ LJ::MemCache::set([$journalu->{'userid'},"talkbody:$memkey"], $comment->{body}); LJ::MemCache::delete( [ $journalu->{userid}, "activeentries:" . $journalu->{userid} ] ); + LJ::MemCache::delete( [ $journalu->{userid}, "screenedcount:$journalu->{userid}:$itemid" ] ) + if $comment->{state} eq 'S'; # dudata my $bytes = length($comment->{subject}) + length($comment->{body}); diff -r 032324f7aa40 -r a7ecd3b0754f htdocs/talkpost.bml --- a/htdocs/talkpost.bml Wed Feb 08 16:44:08 2012 +0800 +++ b/htdocs/talkpost.bml Thu Feb 09 19:41:01 2012 +0800 @@ -363,10 +363,19 @@ my $readurl = LJ::Talk::talkargs($talkurl, LJ::viewing_style_args( %GET ) ); my $replycount = $entry->prop( "replycount" ); - my $readlink_text = BML::ml( "talk.commentsread.counted", + my $readlink_text; + + # show total number of comments, including screened comments if the viewer is allowed to + if ( $remote && LJ::Talk::can_screen( $remote, $u, $up ) && $entry->prop( "hasscreened" ) ) { + my $screenedcount = LJ::Talk::get_screenedcount( $u, $itemid ); + $readlink_text = BML::ml( "talk.commentsread.counted.screened", + { replycount => $replycount, screenedcount => $screenedcount } ); + } else { + $readlink_text = BML::ml( "talk.commentsread.counted", { replycount => $replycount } ); - $readlink_text = BML::ml( "talk.commentsread.nocomments" ) - if $replycount == 0; + $readlink_text = BML::ml( "talk.commentsread.nocomments" ) + if $replycount == 0; + } $ret .= "<p align='center' class='lesstop'><b>(<a href=\"$readurl#comments\">$readlink_text</a>)</b></p>"; diff -r 032324f7aa40 -r a7ecd3b0754f htdocs/talkread.bml --- a/htdocs/talkread.bml Wed Feb 08 16:44:08 2012 +0800 +++ b/htdocs/talkread.bml Thu Feb 09 19:41:01 2012 +0800 @@ -746,16 +746,30 @@ my $readlink; my $replycount = $entry->prop("replycount"); - my $readlink_text = BML::ml( "talk.commentsread.counted", + my $readlink_text; + my $comments_count; + my $totalcount = $replycount; + + # show total number of comments, including screened comments if the viewer is allowed to + if ( $remote && LJ::Talk::can_screen( $remote, $u, $up ) && $entry->prop("hasscreened") ) { + my $screenedcount = LJ::Talk::get_screenedcount( $u, $itemid ); + $totalcount = $replycount + $screenedcount; + $readlink_text = BML::ml( "talk.commentsread.counted.screened", + { replycount => $replycount, screenedcount => $screenedcount } ); + $comments_count = BML::ml( "talk.comments.counted.screened", + { replycount => $replycount, screenedcount => $screenedcount } ); + } else { + $readlink_text = BML::ml( "talk.commentsread.counted", { replycount => $replycount } ); - my $comments_count = BML::ml( "talk.comments.counted", - { replycount => $replycount } ); + $comments_count = BML::ml( "talk.comments.counted", + { replycount => $replycount } ) if $replycount > 0; + } if ( $dthread && $pages == 1 ) { my $readurl = LJ::Talk::talkargs( $talkurl, $style_args ); $readlink = "(<a href='$readurl#comments'>$readlink_text</a>) - "; } else { - $readlink = "($comments_count) - " if $replycount > 0; + $readlink = "($comments_count) - " if $totalcount > 0; } # --------------------------------------------------------------------------------
no subject