X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fprofilenoticestream.php;h=1fde1c6025e2408191284f5ae6b4be93387aa8e5;hb=2d3c19c2547911fcaba253bb6329b4bdfafef21d;hp=7ea653f8c8c2a1bcc31bfabc6ad033c5f643c2d0;hpb=9f1603462dce7a24d432698c4f46d7dcf1bf7c4f;p=quix0rs-gnu-social.git diff --git a/lib/profilenoticestream.php b/lib/profilenoticestream.php index 7ea653f8c8..1fde1c6025 100644 --- a/lib/profilenoticestream.php +++ b/lib/profilenoticestream.php @@ -47,10 +47,60 @@ if (!defined('STATUSNET')) { class ProfileNoticeStream extends ScopingNoticeStream { - function __construct($profile) + var $streamProfile; + var $userProfile; + + function __construct($profile, $userProfile = -1) { + if (is_int($userProfile) && $userProfile == -1) { + $userProfile = Profile::current(); + } + $this->streamProfile = $profile; + $this->userProfile = $userProfile; parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($profile), - 'profile:notice_ids:' . $profile->id)); + 'profile:notice_ids:' . $profile->id), + $userProfile); + } + + function getNoticeIds($offset, $limit, $since_id, $max_id) + { + if ($this->impossibleStream()) { + return array(); + } else { + return parent::getNoticeIds($offset, $limit, $since_id, $max_id); + } + } + + function getNotices($offset, $limit, $sinceId = null, $maxId = null) + { + if ($this->impossibleStream()) { + return new ArrayWrapper(array()); + } else { + return parent::getNotices($offset, $limit, $sinceId, $maxId); + } + } + + function impossibleStream() + { + $user = User::staticGet('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->userProfile) || !$this->userProfile->hasRole(Profile_role::MODERATOR))) { + return true; + } + } + + return false; } }