X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Fprofilenoticestream.php;h=1fa795d32090a55866c49f9221757ab7c089fdcb;hb=996345088e8d57cf39fa38129ab50ff02918a275;hp=ca54ad4892b7eb81976b12e2d374048ad1f665d3;hpb=84984fdbfecdd79630801e2a6ca5b5e9e4b725a1;p=quix0rs-gnu-social.git diff --git a/lib/profilenoticestream.php b/lib/profilenoticestream.php index ca54ad4892..1fa795d320 100644 --- a/lib/profilenoticestream.php +++ b/lib/profilenoticestream.php @@ -4,7 +4,7 @@ * Copyright (C) 2011, StatusNet, Inc. * * Stream of notices by a profile - * + * * PHP version 5 * * This program is free software: you can redistribute it and/or modify @@ -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=null, $max_id=null) + { + if ($this->impossibleStream()) { + return array(); + } else { + 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 impossibleStream() + { + $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->userProfile) || (($this->userProfile->id !== $this->streamProfile->id) && !$this->userProfile->hasRight(Right::REVIEWSPAM)))) { + return true; + } + } + + return false; } } @@ -71,6 +121,7 @@ class RawProfileNoticeStream extends NoticeStream function __construct($profile) { + parent::__construct(); $this->profile = $profile; }