]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Optionally hide spam from timelines
authorEvan Prodromou <evan@status.net>
Wed, 21 Mar 2012 14:17:11 +0000 (10:17 -0400)
committerEvan Prodromou <evan@status.net>
Wed, 21 Mar 2012 14:17:11 +0000 (10:17 -0400)
For sites with a lot of spam, this will hide that spam from timelines for everyone but moderators.

classes/Notice.php
lib/default.php
lib/noticelist.php

index 68351477f03d388a6a7fde41862c4667d7dd17d1..a944830e51c17d7d44ca77ba75941b3cc9656ac6 100644 (file)
@@ -2387,75 +2387,101 @@ class Notice extends Managed_DataObject
 
         // If there's no scope, anyone (even anon) is in scope.
 
-        if ($scope == 0) {
-            return true;
-        }
+        if ($scope == 0) { // Not private
 
-        // If there's scope, anon cannot be in scope
+            return !$this->isHiddenSpam();
 
-        if (empty($profile)) {
-            return false;
-        }
+        } else { // Private, somehow
 
-        // Author is always in scope
+            // If there's scope, anon cannot be in scope
 
-        if ($this->profile_id == $profile->id) {
-            return true;
-        }
+            if (empty($profile)) {
+                return false;
+            }
 
-        // Only for users on this site
+            // Author is always in scope
 
-        if ($scope & Notice::SITE_SCOPE) {
-            $user = $profile->getUser();
-            if (empty($user)) {
-                return false;
+            if ($this->profile_id == $profile->id) {
+                return true;
+            }
+
+            // Only for users on this site
+
+            if ($scope & Notice::SITE_SCOPE) {
+                $user = $profile->getUser();
+                if (empty($user)) {
+                    return false;
+                }
             }
-        }
 
-        // Only for users mentioned in the notice
+            // Only for users mentioned in the notice
 
-        if ($scope & Notice::ADDRESSEE_SCOPE) {
+            if ($scope & Notice::ADDRESSEE_SCOPE) {
 
-                       $repl = Reply::pkeyGet(array('notice_id' => $this->id,
-                                                                                'profile_id' => $profile->id));
+                $repl = Reply::pkeyGet(array('notice_id' => $this->id,
+                                             'profile_id' => $profile->id));
                                                                                 
-            if (empty($repl)) {
-                return false;
+                if (empty($repl)) {
+                    return false;
+                }
             }
-        }
 
-        // Only for members of the given group
+            // Only for members of the given group
 
-        if ($scope & Notice::GROUP_SCOPE) {
+            if ($scope & Notice::GROUP_SCOPE) {
 
-            // XXX: just query for the single membership
+                // XXX: just query for the single membership
 
-            $groups = $this->getGroups();
+                $groups = $this->getGroups();
 
-            $foundOne = false;
+                $foundOne = false;
 
-            foreach ($groups as $group) {
-                if ($profile->isMember($group)) {
-                    $foundOne = true;
-                    break;
+                foreach ($groups as $group) {
+                    if ($profile->isMember($group)) {
+                        $foundOne = true;
+                        break;
+                    }
+                }
+
+                if (!$foundOne) {
+                    return false;
                 }
             }
 
-            if (!$foundOne) {
-                return false;
+            // Only for followers of the author
+
+            $author = null;
+
+            if ($scope & Notice::FOLLOWER_SCOPE) {
+
+                $author = $this->getProfile();
+        
+                if (!Subscription::exists($profile, $author)) {
+                    return false;
+                }
             }
+
+            return !$this->isHiddenSpam();
         }
+    }
+
+    function isHiddenSpam() {
 
-        // Only for followers of the author
+        
+        // Hide posts by silenced users from everyone but moderators.
+
+        if (common_config('notice', 'hidespam')) {
 
-        if ($scope & Notice::FOLLOWER_SCOPE) {
             $author = $this->getProfile();
-            if (!Subscription::exists($profile, $author)) {
-                return false;
+
+            if ($author->hasRole(Profile_role::SILENCED)) {
+                if (!$profile->hasRole(Profile_role::MODERATOR)) {
+                    return true;
+                }
             }
         }
 
-        return true;
+        return false;
     }
 
     static function groupsFromText($text, $profile)
index b20af476d659bf016f66952a41c9167a4b9bc975..82ffe80a5db4a51d678950d04a4861a94c756233 100644 (file)
@@ -288,7 +288,8 @@ $default =
               'gc_limit' => 1000), // max sessions to expire at a time
         'notice' =>
         array('contentlimit' => null,
-              'defaultscope' => null), // null means 1 if site/private, 0 otherwise
+              'defaultscope' => null, // null means 1 if site/private, 0 otherwise
+              'hidespam' => false), // Whether to hide silenced users from timelines
         'message' =>
         array('contentlimit' => null),
         'location' =>
index 7f38cf005b29469dddca30197946a0cc78da5b4d..5df123fb5f9102303886931f7d0cdfa5e8567cbb 100644 (file)
@@ -151,6 +151,20 @@ class NoticeList extends Widget
                 Memcached_DataObject::pivotGet('Notice', 'repeat_of', $ids, array('profile_id' => $p->id));
             }
 
+            if (common_config('notice', 'hidespam')) {
+
+                $pids = array();
+
+                foreach ($profiles as $profile) {
+                    $pids[] = $profile->id;
+                }
+                
+                Memcached_DataObject::pivotGet('Profile_role',
+                                               'profile_id',
+                                               $pids,
+                                               array('role' => Profile_role::SILENCED));
+            }
+
             Event::handle('EndNoticeListPrefill', array(&$notices, &$profiles, $avatarSize));
         }
     }