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
48 function __construct(Profile $target, Profile $scoped=null)
50 $this->target = $target;
51 parent::__construct(new CachingNoticeStream(new RawProfileNoticeStream($target),
52 'profile:notice_ids:' . $target->getID()),
56 function getNoticeIds($offset, $limit, $since_id=null, $max_id=null)
58 if ($this->impossibleStream()) {
61 return parent::getNoticeIds($offset, $limit, $since_id, $max_id);
65 function getNotices($offset, $limit, $since_id=null, $max_id=null)
67 if ($this->impossibleStream()) {
68 throw new PrivateStreamException($this->target, $this->scoped);
70 return parent::getNotices($offset, $limit, $since_id, $max_id);
74 function impossibleStream()
76 if (!$this->target->readableBy($this->scoped)) {
77 // cannot read because it's a private stream and either noone's logged in or they are not subscribers
81 // If it's a spammy stream, and no user or not a moderator
83 if (common_config('notice', 'hidespam')) {
84 // if this is a silenced user
85 if ($this->target->hasRole(Profile_role::SILENCED)
86 // and we are either not logged in
87 && (!$this->scoped instanceof Profile
88 // or if we are, we are not logged in as the target, and we don't have right to review spam
89 || (!$this->scoped->sameAs($this->target) && !$this->scoped->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 $target)
117 parent::__construct();
118 $this->target = $target;
121 function getNoticeIds($offset, $limit, $since_id, $max_id)
123 $notice = new Notice();
125 $notice->profile_id = $this->target->getID();
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;