fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-10-02 05:44 pm

[dw-free] Show circle on interest search

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

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

Allow to filter interests by people and communities in your circle only.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/DW/Controller/Search/Interests.pm
  • cgi-bin/LJ/Keywords.pm
  • views/interests/int.tt.text
--------------------------------------------------------------------------------
diff -r 052068eab16d -r de3152cb1398 cgi-bin/DW/Controller/Search/Interests.pm
--- a/cgi-bin/DW/Controller/Search/Interests.pm	Mon Oct 03 01:29:38 2011 +0800
+++ b/cgi-bin/DW/Controller/Search/Interests.pm	Mon Oct 03 01:43:57 2011 +0800
@@ -292,10 +292,13 @@
         $rv->{intcount} = $intcount;
 
         # filtering by account type
-        $rv->{type_list} = [ 'none', 'P', 'C', 'I' ];
+        my @type_args = ( 'none', 'P', 'C', 'I' );
+        push @type_args, 'F' if $remote;  # no circle if not logged in
+        $rv->{type_list} = \@type_args;
 
         my $type = $args->{type};
-        $type = 'none' unless $type && $type =~ /^[PCI]$/;
+        $type = 'none' unless $type && $type =~ /^[PCIF]$/;
+        $type = 'none' if $type eq 'F' && ! $remote;  # just in case
 
         # constructor for filter links
         $rv->{type_link} = sub {
@@ -306,7 +309,8 @@
 
         # determine which account types we need to search for
         my $type_opts = {};
-        my %opt_map = ( C => 'nousers', P => 'nocomms', I => 'nocomms' );
+        my %opt_map = ( C => 'nousers', P => 'nocomms',
+                        I => 'nocomms', F => 'circle' );
         $type_opts = { $opt_map{$type} => 1 } if defined $opt_map{$type};
 
         my @uids = LJ::users_with_all_ints( [$intid], $type_opts );
@@ -328,7 +332,9 @@
 
         my $typefilter = sub {
             $rv->{comm_count}++ if $_[0]->is_community;
-            return $type eq 'none' ? 1 : $_[0]->journaltype eq $type;
+            return 1 if $type eq 'none';
+            return 1 if $type eq 'F';  # already filtered
+            return $_[0]->journaltype eq $type;
         };
 
         my $should_show = sub {
diff -r 052068eab16d -r de3152cb1398 cgi-bin/LJ/Keywords.pm
--- a/cgi-bin/LJ/Keywords.pm	Mon Oct 03 01:29:38 2011 +0800
+++ b/cgi-bin/LJ/Keywords.pm	Mon Oct 03 01:43:57 2011 +0800
@@ -126,19 +126,27 @@
     push @tables, 'comminterests' unless $opts->{nocomms};
     return unless @tables;
 
+    # allow restricting to user's circle
+    my $cids;
+    if ( $opts->{circle} && ( my $u = LJ::get_remote() ) ) {
+        my @circle = ( $u->circle_userids, $u->member_of_userids, $u->id );
+        $cids = join ',', @circle;
+    }
+
     my $dbr = LJ::get_db_reader();
     my $qs = join ',', map { '?' } @intids;
     my @uids;
 
     foreach ( @tables ) {
         my $q = "SELECT userid FROM $_ WHERE intid IN ($qs)";
+        $q .= " AND userid IN ($cids)" if $cids;
         my $uref = $dbr->selectall_arrayref( $q, undef, @intids );
         die $dbr->errstr if $dbr->err;
 
         # Count the number of times the uid appears.
         # If it's the same as the number of interests, it has all of them.
         my %ucount;
-        $ucount{$_}++ foreach map { $_->[0] } @$uref;
+        $ucount{ $_->[0] }++ foreach @$uref;
         push @uids, grep { $ucount{$_} == scalar @intids } keys %ucount;
     }
 
diff -r 052068eab16d -r de3152cb1398 views/interests/int.tt.text
--- a/views/interests/int.tt.text	Mon Oct 03 01:29:38 2011 +0800
+++ b/views/interests/int.tt.text	Mon Oct 03 01:43:57 2011 +0800
@@ -5,6 +5,8 @@
 
 .filterlink.c=Communities Only
 
+.filterlink.f=Circle Only
+
 .filterlink.i=OpenIDs Only
 
 .filterlink.label=Show:
--------------------------------------------------------------------------------