mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2010-04-20 08:42 am

[dw-free] Screened comment conversations

[commit: http://hg.dwscoalition.org/dw-free/rev/b91dec6eeaab]

http://bugs.dwscoalition.org/show_bug.cgi?id=2275

Alter the way screened comments work. In addition to your own screened
comments, you can now see comments made by the journal owner or community
administrators that are direct replies to one of your comments. You may
also now reply to any screened comment you can see, and keep your reply
screened.

Patch by [personal profile] yvi.

Files modified:
  • cgi-bin/LJ/Comment.pm
  • cgi-bin/LJ/S2/ReplyPage.pm
  • cgi-bin/LJ/Talk.pm
  • htdocs/talkpost.bml
  • htdocs/talkread.bml
--------------------------------------------------------------------------------
diff -r 18a840d5d368 -r b91dec6eeaab cgi-bin/LJ/Comment.pm
--- a/cgi-bin/LJ/Comment.pm	Mon Apr 19 22:22:51 2010 -0700
+++ b/cgi-bin/LJ/Comment.pm	Tue Apr 20 08:42:32 2010 +0000
@@ -929,9 +929,11 @@ sub visible_to {
 
     # screened comment
     return 0 if $self->is_screened &&
-                !( LJ::can_manage($u, $self->journal)           # owns the journal
-                   || LJ::u_equals($u, $self->poster)           # posted the comment
-                   || LJ::u_equals($u, $self->entry->poster )); # posted the entry
+                !( LJ::can_manage( $u, $self->journal )           # owns the journal
+                   || LJ::u_equals( $u, $self->poster )           # posted the comment
+                   || LJ::u_equals( $u, $self->entry->poster ) # posted the entry
+                   || ( $self->parent && LJ::u_equals( $u, $self->parent->poster ) && LJ::can_manage( $self->poster, $self->journal ) ) );
+                        # person this is in reply to, as long as this comment was by a moderator
 
     # comments from suspended users aren't visible
     return 0 if $self->poster && $self->poster->is_suspended;
diff -r 18a840d5d368 -r b91dec6eeaab cgi-bin/LJ/S2/ReplyPage.pm
--- a/cgi-bin/LJ/S2/ReplyPage.pm	Mon Apr 19 22:22:51 2010 -0700
+++ b/cgi-bin/LJ/S2/ReplyPage.pm	Tue Apr 20 08:42:32 2010 +0000
@@ -75,6 +75,7 @@ sub ReplyPage
     my $replyto = $s2entry;
     my $editid = $get->{edit} ? $get->{edit} : 0;
     my $parpost;
+    my $parentcomment;
 
     my $comment;
     my %comment_values;
@@ -129,13 +130,14 @@ sub ReplyPage
             $parpost = $db->selectrow_hashref($sql);
             last if $parpost;
         }
+        my $parentcomment = LJ::Comment->new( $u, jtalkid => $re_talkid );
         unless ($parpost and $parpost->{'state'} ne 'D') {
             # FIXME: This is a hack. See below...
 
             $opts->{status} = "404 Not Found";
             return "<p>This comment has been deleted; you cannot reply to it.</p>";
         }
-        if ($parpost->{'state'} eq 'S' && !LJ::Talk::can_unscreen($remote, $u, $s2entry->{'poster'}->{'user'}, undef)) {
+        if ( $parpost->{state} eq 'S' && !$parentcomment->visible_to( $remote ) ) {
             $opts->{'handler_return'} = 403;
             return;
         }
diff -r 18a840d5d368 -r b91dec6eeaab cgi-bin/LJ/Talk.pm
--- a/cgi-bin/LJ/Talk.pm	Mon Apr 19 22:22:51 2010 -0700
+++ b/cgi-bin/LJ/Talk.pm	Tue Apr 20 08:42:32 2010 +0000
@@ -331,10 +331,6 @@ sub can_screen {
 
 sub can_unscreen {
     return LJ::Talk::can_screen(@_);
-}
-
-sub can_view_screened {
-    return LJ::Talk::can_delete(@_);
 }
 
 sub can_freeze {
@@ -962,11 +958,24 @@ sub load_comments
             # see if we should ideally show it or not.  even if it's
             # zero, we'll still show it if it has any children (but we won't show content)
             my $should_show = $post->{'state'} eq 'D' ? 0 : 1;
+            my $parenttalkid = $post->{parenttalkid};
             unless ($viewall) {
                 $should_show = 0 if
-                    $post->{'state'} eq "S" && ! ($remote && ($remote->{'userid'} == $uposterid ||
-                                                              $remote->{'userid'} == $post->{'posterid'} ||
-                                                              LJ::can_manage($remote, $u) ));
+                    # can view if not screened, or if screened and some conditions apply
+                    $post->{state} eq "S" &&
+                    !( $remote &&
+                        ( $remote->{userid} == $uposterid || # made in remote's journal
+                            $remote->{userid} == $post->{posterid} || # made by remote
+                            LJ::can_manage( $remote, $u ) || # made in a journal remote manages
+                            (
+                              # remote authored the parent, and this comment is by an admin
+                              exists $posts->{$parenttalkid} &&
+                              $posts->{$parenttalkid}->{posterid} &&
+                              $posts->{$parenttalkid}->{posterid} == $remote->{userid} &&
+                              LJ::can_manage( $post->{posterid}, $u )
+                            )
+                        )
+                    );
             }
             $post->{'_show'} = $should_show;
             $post_count += $should_show;
@@ -1189,6 +1198,7 @@ sub talkform {
     }
 
     my $pics = LJ::Talk::get_subjecticons();
+    my $entry = LJ::Entry->new( $journalu, ditemid => $opts->{ditemid} );
 
     # once we clean out talkpost.bml, this will need to be changed.
     BML::set_language_scope('/talkpost.bml');
@@ -1327,7 +1337,6 @@ sub talkform {
     } else { # if not edit
 
     if ($journalu->{'opt_whocanreply'} eq "all") {
-        my $entry = LJ::Entry->new($journalu, ditemid => $opts->{ditemid});
 
         if ($entry && $entry->security ne "public") {
             $ret .= "<tr valign='middle'>";
@@ -1760,9 +1769,9 @@ QQ
     $ret .= "</td><td style='width: 90%'>";
     $ret .= "<textarea class='textbox' rows='10' cols='75' wrap='soft' name='body' id='commenttext'>" . LJ::ehtml($form->{body}) . "</textarea><br />";
 
-    # if parent comment is screened, give option to unscreen it
+    # if parent comment is screened, and user can unscreen, give option to unscreen it
     # default is not to unscreen
-    if ( $parpost->{state} eq "S" ) {
+    if ( $parpost->{state} eq "S" && LJ::Talk::can_unscreen( $remote, $journalu, $entry->poster ) ) {
         $ret .= "<label for='unscreen_parent'>$BML::ML{'.opt.unscreenparent'}</label>";
         $ret .= LJ::html_check(
                 {
@@ -3142,8 +3151,6 @@ sub init {
     }
 
     # If the reply is to a comment, check that it exists.
-    # if it's screened, check that the user has permission to
-    # reply and unscreen it
 
     my $parpost;
     my $partid = $form->{'parenttalkid'}+0;
@@ -3152,15 +3159,6 @@ sub init {
         $parpost = LJ::Talk::get_talk2_row($dbcr, $journalu->{userid}, $partid);
         unless ($parpost) {
             $bmlerr->("$SC.error.noparent");
-        }
-
-        # can't use $remote because we may get here
-        # with a reply from email. so use $up instead of $remote
-        # in the call below.
-
-        if ($parpost && $parpost->{'state'} eq "S" &&
-            !LJ::Talk::can_unscreen($up, $journalu, $init->{entryu}, $init->{entryu}{'user'})) {
-            $bmlerr->("$SC.error.screened");
         }
     }
     $init->{parpost} = $parpost;
diff -r 18a840d5d368 -r b91dec6eeaab htdocs/talkpost.bml
--- a/htdocs/talkpost.bml	Mon Apr 19 22:22:51 2010 -0700
+++ b/htdocs/talkpost.bml	Tue Apr 20 08:42:32 2010 +0000
@@ -90,7 +90,7 @@ body<=
     {
         my $qparentid = $init->{'replyto'};
 
-        my $sql = "SELECT t.posterid, t.nodetype, t.nodeid AS 'itemid', ".
+        my $sql = "SELECT t.posterid, t.nodetype, t.jtalkid, t.nodeid AS 'itemid', ".
             "UNIX_TIMESTAMP()-UNIX_TIMESTAMP(t.datepost) AS 'secondsold', ".
             "t.state, l.anum FROM talk2 t, log2 l WHERE l.journalid=$u->{'userid'} AND ".
             "l.jitemid=t.nodeid AND t.journalid=$u->{'userid'} AND t.jtalkid=$qparentid";
@@ -184,9 +184,9 @@ body<=
         if $entry && $entry->is_suspended;
 
     # checked screened post
+    my $parentcomment = LJ::Comment->new( $u, jtalkid => $parpost->{jtalkid} );
     return "<?h1 $ML{'Error'} h1?><?p $ML{'.error.noreply_screened'} p?>"
-        if $parpost->{'state'} eq "S"
-           && ! LJ::Talk::can_unscreen($remote, $u, $up, ($ur ? $ur->{'user'} : undef));
+        if $parpost->{'state'} eq "S" && !$parentcomment->visible_to( $remote );
 
     return "<?h1 $ML{'Error'} h1?><?p $ML{'.error.noreply_deleted'} p?>"
         if $parpost->{'state'} eq "D";
diff -r 18a840d5d368 -r b91dec6eeaab htdocs/talkread.bml
--- a/htdocs/talkread.bml	Mon Apr 19 22:22:51 2010 -0700
+++ b/htdocs/talkread.bml	Tue Apr 20 08:42:32 2010 +0000
@@ -700,13 +700,10 @@ body<=
                     if ($bp) {
                         $ret .= "(<a href='$bp'>$T{'replythis'}</a>) ";
                     } else {
-                       if ($post->{state} eq 'S') {
-                           if ( LJ::Talk::can_unscreen( $remote, LJ::load_userid( $item->{ownerid} ), $item, $u ) ) {
-                               # if user can unscreen, they can reply, choosing whether to unscreen or not
-                               $ret .= "(" . LJ::make_qr_link($dtid, $post->{subject}, $T{replythis}, $replyurl) .  ") ";
-                           } else {
-                               $ret .= "($T{ 'screened' })";
-                           }
+                        if ( $post->{state} eq 'S' ) {
+                            # if the user can see the comment, they can also reply
+                            # if they can also unscreen, they are given the option to reply and unscreen
+                            $ret .= "(" . LJ::make_qr_link( $dtid, $post->{subject}, $T{replythis}, $replyurl ) .  ") ";
                        } else {
                            $ret .= "(" . LJ::make_qr_link($dtid, $post->{'subject'}, $T{'replythis'}, $replyurl) .  ") ";
                        }
@@ -745,9 +742,6 @@ body<=
                 $ret .= "<a name='$htmlid'></a><span id='$htmlid'><table ><tbody><tr>";
                 $ret .= "<td><img src='$LJ::IMGPREFIX/dot.gif' height='1' width='" . ($opts->{'depth'} * 25) . "'></td>";
                 $ret .= "<td>";
-                if ($post->{'state'} eq 'S') {
-                    $ret .= "($T{'screened'}) ";
-                }
                 if ($post->{'state'} eq 'F') {
                     $ret .= "($T{'frozen'}) ";
                 }
--------------------------------------------------------------------------------
yvi: Kaylee half-smiling, looking very pretty (Default)

[personal profile] yvi 2010-04-20 10:30 am (UTC)(link)
Yay! :)
turlough: Gabe Saporta doing thumbs-up ((cs) gabe approves)

[personal profile] turlough 2010-04-20 01:06 pm (UTC)(link)
Very cool!!
azurelunatic: "I survived Dreamwidth closed beta" (closed beta)

[personal profile] azurelunatic 2010-04-20 02:59 pm (UTC)(link)
OH MY GOD THIS IS GOING TO BE SWEET.
sophie: A cartoon-like representation of a girl standing on a hill, with brown hair, blue eyes, a flowery top, and blue skirt. ☀ (Default)

[personal profile] sophie 2010-04-20 05:30 pm (UTC)(link)
The only "problem" with this patch is that I'll need to bear in mind that this doesn't work on LJ, and only reply accordingly. Otherwise it's OMG SQUEE-worthy. :DDD