3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Stream of notices by a profile
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Affero General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Affero General Public License for more details.
20 * You should have received a copy of the GNU Affero General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 * @author Evan Prodromou <evan@status.net>
26 * @copyright 2011 StatusNet, Inc.
27 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28 * @link http://status.net/
31 if (!defined('GNUSOCIAL')) { exit(1); }
34 * Stream of notices by a profile
38 * @author Evan Prodromou <evan@status.net>
39 * @copyright 2011 StatusNet, Inc.
40 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
41 * @link http://status.net/
44 class ProfileNoticeStream extends ScopingNoticeStream
49 function __construct($profile, $userProfile = -1)
51 if (is_int($userProfile) && $userProfile == -1) {
52 $userProfile = Profile::current();
54 $this->streamProfile = $profile;
55 $this->userProfile = $userProfile;
56 parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($profile),
57 'profile:notice_ids:' . $profile->id),
61 function getNoticeIds($offset, $limit, $since_id=null, $max_id=null)
63 if ($this->impossibleStream()) {
66 return parent::getNoticeIds($offset, $limit, $since_id, $max_id);
70 function getNotices($offset, $limit, $since_id=null, $max_id=null)
72 if ($this->impossibleStream()) {
73 throw new PrivateStreamException($this->streamProfile, $this->userProfile);
75 return parent::getNotices($offset, $limit, $since_id, $max_id);
79 function impossibleStream()
81 if (!$this->streamProfile->readableBy($this->userProfile)) {
82 // cannot read because it's a private stream and either noone's logged in or they are not subscribers
86 // If it's a spammy stream, and no user or not a moderator
88 if (common_config('notice', 'hidespam')) {
89 if ($this->streamProfile->hasRole(Profile_role::SILENCED) &&
90 (empty($this->userProfile) || (($this->userProfile->id !== $this->streamProfile->id) && !$this->userProfile->hasRight(Right::REVIEWSPAM)))) {
100 * Raw stream of notices by a profile
104 * @author Evan Prodromou <evan@status.net>
105 * @copyright 2011 StatusNet, Inc.
106 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
107 * @link http://status.net/
110 class RawProfileNoticeStream extends NoticeStream
113 protected $selectVerbs = array(); // select all verbs
115 function __construct($profile)
117 parent::__construct();
118 $this->profile = $profile;
121 function getNoticeIds($offset, $limit, $since_id, $max_id)
123 $notice = new Notice();
125 $notice->profile_id = $this->profile->id;
127 $notice->selectAdd();
128 $notice->selectAdd('id');
130 Notice::addWhereSinceId($notice, $since_id);
131 Notice::addWhereMaxId($notice, $max_id);
133 self::filterVerbs($notice, $this->selectVerbs);
135 $notice->orderBy('created DESC, id DESC');
137 if (!is_null($offset)) {
138 $notice->limit($offset, $limit);
145 while ($notice->fetch()) {
146 $ids[] = $notice->id;