]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/profilenoticestream.php
Misses this file to merge. I like the comments.
[quix0rs-gnu-social.git] / lib / profilenoticestream.php
index d2948e60c859041c754bf6a634a89b221323003b..1fa795d32090a55866c49f9221757ab7c089fdcb 100644 (file)
@@ -48,6 +48,7 @@ if (!defined('STATUSNET')) {
 class ProfileNoticeStream extends ScopingNoticeStream
 {
     var $streamProfile;
+    var $userProfile;
 
     function __construct($profile, $userProfile = -1)
     {
@@ -55,35 +56,51 @@ class ProfileNoticeStream extends ScopingNoticeStream
             $userProfile = Profile::current();
         }
         $this->streamProfile = $profile;
+        $this->userProfile   = $userProfile;
         parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($profile),
                                                     'profile:notice_ids:' . $profile->id),
                             $userProfile);
     }
 
-    function getNoticeIds($offset, $limit, $since_id, $max_id)
+    function getNoticeIds($offset, $limit, $since_id=null, $max_id=null)
     {
-        // Sanity check
-        if (common_config('notice', 'hidespam')) {
-            if ($this->streamProfile->hasRole(Profile_role::SILENCED) &&
-                (empty($this->profile) || !$this->profile->hasRole(Profile_role::MODERATOR))) {
-                throw new ClientException(_("This account silenced by moderators."), 403);
-            }
+        if ($this->impossibleStream()) {
+            return array();
+        } else {
+            return parent::getNoticeIds($offset, $limit, $since_id, $max_id);
         }
+    }
 
-        return parent::getNoticeIds($offset, $limit, $since_id, $max_id);
+    function getNotices($offset, $limit, $since_id=null, $max_id=null)
+    {
+        if ($this->impossibleStream()) {
+            return new ArrayWrapper(array());
+        } else {
+            return parent::getNotices($offset, $limit, $since_id, $max_id);
+        }
     }
 
-    function getNotices($offset, $limit, $sinceId = null, $maxId = null)
+    function impossibleStream() 
     {
-        // Sanity check
+        $user = User::getKV('id', $this->streamProfile->id);
+
+        // If it's a private stream, and no user or not a subscriber
+
+        if (!empty($user) && $user->private_stream && 
+            (empty($this->userProfile) || !$this->userProfile->isSubscribed($this->streamProfile))) {
+            return true;
+        }
+
+        // If it's a spammy stream, and no user or not a moderator
+
         if (common_config('notice', 'hidespam')) {
             if ($this->streamProfile->hasRole(Profile_role::SILENCED) &&
-                (empty($this->profile) || !$this->profile->hasRole(Profile_role::MODERATOR))) {
-                throw new ClientException(_("This account silenced by moderators."), 403);
+                (empty($this->userProfile) || (($this->userProfile->id !== $this->streamProfile->id) && !$this->userProfile->hasRight(Right::REVIEWSPAM)))) {
+                return true;
             }
         }
 
-        return parent::getNotices($offset, $limit, $sinceId, $maxId);
+        return false;
     }
 }
 
@@ -104,6 +121,7 @@ class RawProfileNoticeStream extends NoticeStream
 
     function __construct($profile)
     {
+        parent::__construct();
         $this->profile = $profile;
     }