fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-08-19 03:49 am

[dw-free] Comment parameter to journal entry views

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

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

Allow filtering comments by ?comments=screened, ?comments=frozen,
?comments=visible.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/S2/EntryPage.pm
  • cgi-bin/LJ/Talk.pm
  • htdocs/talkread.bml
--------------------------------------------------------------------------------
diff -r bd0e690c7319 -r d1b4f5148736 cgi-bin/LJ/S2/EntryPage.pm
--- a/cgi-bin/LJ/S2/EntryPage.pm	Fri Aug 19 11:08:59 2011 +0800
+++ b/cgi-bin/LJ/S2/EntryPage.pm	Fri Aug 19 11:44:02 2011 +0800
@@ -113,6 +113,7 @@
         'up' => LJ::load_user($s2entry->{'poster'}->{'user'}),
         'viewall' => $viewall,
         'expand_all' => $opts->{expand_all},
+        'filter' => $get->{comments},
     };
 
     my $userlite_journal = UserLite($u);
diff -r bd0e690c7319 -r d1b4f5148736 cgi-bin/LJ/Talk.pm
--- a/cgi-bin/LJ/Talk.pm	Fri Aug 19 11:08:59 2011 +0800
+++ b/cgi-bin/LJ/Talk.pm	Fri Aug 19 11:44:02 2011 +0800
@@ -903,6 +903,8 @@
 #   flat -- boolean:  if set, threading isn't done, and it's just a flat chrono view
 #   up -- [optional] hashref of user object who posted the thing being replied to
 #         only used to make things visible which would otherwise be screened?
+#   filter -- [optional] value of comments getarg (screened|frozen|visible)
+#         used to hide comments not matching the specified type
 #   out_error -- set by us if there's an error code:
 #        nodb:  database unavailable
 #        noposts:  no posts to load
@@ -966,13 +968,28 @@
                 $post->{'parenttalkid'} = 0;
             }
 
+            # grab the comment object for method calls
+            my $pobj = LJ::Comment->new( $u, jtalkid => $post->{talkid} );
+
             # 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} && $post->{state} eq 'D' ? 0 : 1;
+            my $should_show = ! $pobj->is_deleted;
             my $parenttalkid = $post->{parenttalkid};
             unless ( $viewall ) {
+                # first check to see if a filter has been requested
+                my %filtermap = (
+                    screened => sub { return $pobj->is_screened },
+                    frozen => sub { return $pobj->is_frozen },
+                    visible => sub { return $pobj->visible_to( $remote ) },
+                );
+                if ( $should_show && $opts->{filter} && exists $filtermap{ $opts->{filter} } ) {
+                    $should_show = $filtermap{ $opts->{filter} }->();
+                }
+
+                # then check for comment owner/journal owner
                 my $poster = LJ::load_userid( $post->{posterid} );
-                $should_show = 0 if
+                $should_show = 0 if $should_show &&     # short circuit, and check the following conditions
+                                                        # only if we wanted to show in the first place
                     # can view if not screened, or if screened and some conditions apply
                     $post->{state} eq "S" &&
                     ! ( $remote &&
diff -r bd0e690c7319 -r d1b4f5148736 htdocs/talkread.bml
--- a/htdocs/talkread.bml	Fri Aug 19 11:08:59 2011 +0800
+++ b/htdocs/talkread.bml	Fri Aug 19 11:44:02 2011 +0800
@@ -353,6 +353,7 @@
         'userref' => \%user,
         'up' => $up,
         'viewall' => $viewall,
+        'filter' => $GET{comments},
     };
 
     my @comments = LJ::Talk::load_comments($u, $remote, "L", $itemid, $opts);
--------------------------------------------------------------------------------

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org