3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Stream of notices for a profile's "all" feed
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/>.
23 * @category NoticeStream
25 * @author Evan Prodromou <evan@status.net>
26 * @author Mikael Nordfeldth <mmn@hethane.se>
27 * @copyright 2011 StatusNet, Inc.
28 * @copyright 2014 Free Software Foundation, Inc.
29 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
30 * @link http://status.net/
33 if (!defined('GNUSOCIAL')) { exit(1); }
36 * Stream of notices for a profile's "all" feed
40 * @author Evan Prodromou <evan@status.net>
41 * @author Mikael Nordfeldth <mmn@hethane.se>
42 * @copyright 2011 StatusNet, Inc.
43 * @copyright 2014 Free Software Foundation, Inc.
44 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45 * @link http://status.net/
47 class InboxNoticeStream extends ScopingNoticeStream
52 * @param Profile $target Profile to get a stream for
53 * @param Profile $scoped Currently scoped profile (if null, it is fetched)
55 function __construct(Profile $target, Profile $scoped=null)
57 if ($scoped === null) {
58 $scoped = Profile::current();
60 // FIXME: we don't use CachingNoticeStream - but maybe we should?
61 parent::__construct(new CachingNoticeStream(new RawInboxNoticeStream($target), 'profileall'), $scoped);
66 * Raw stream of notices for the target's inbox
70 * @author Evan Prodromou <evan@status.net>
71 * @copyright 2011 StatusNet, Inc.
72 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
73 * @link http://status.net/
75 class RawInboxNoticeStream extends NoticeStream
77 protected $target = null;
78 protected $inbox = null;
80 protected $selectVerbs = array();
85 * @param Profile $target Profile to get a stream for
87 function __construct(Profile $target)
89 parent::__construct();
90 $this->target = $target;
96 * @param int $offset Offset from start
97 * @param int $limit Limit of number to get
98 * @param int $since_id Since this notice
99 * @param int $max_id Before this notice
101 * @return Array IDs found
103 function getNoticeIds($offset, $limit, $since_id, $max_id)
105 $notice = new Notice();
106 $notice->selectAdd();
107 $notice->selectAdd('id');
108 $notice->whereAdd(sprintf('notice.created > "%s"', $notice->escape($this->target->created)));
109 // Reply:: is a table of mentions
110 // Subscription:: is a table of subscriptions (every user is subscribed to themselves)
112 sprintf('notice.id IN (SELECT notice_id FROM reply WHERE profile_id=%1$d) ' .
113 'OR notice.profile_id IN (SELECT subscribed FROM subscription WHERE subscriber=%1$d) ' .
114 'OR notice.id IN (SELECT notice_id FROM group_inbox WHERE group_id IN (SELECT group_id FROM group_member WHERE profile_id=%1$d))' .
115 'OR notice.id IN (SELECT notice_id FROM attention WHERE profile_id=%1$d)',
118 if (!empty($since_id)) {
119 $notice->whereAdd(sprintf('notice.id > %d', $since_id));
121 if (!empty($max_id)) {
122 $notice->whereAdd(sprintf('notice.id <= %d', $max_id));
125 self::filterVerbs($notice, $this->selectVerbs);
127 $notice->limit($offset, $limit);
128 // notice.id will give us even really old posts, which were
129 // recently imported. For example if a remote instance had
130 // problems and just managed to post here. Another solution
131 // would be to have a 'notice.imported' field and order by it.
132 $notice->orderBy('notice.id DESC');
134 if (!$notice->find()) {
138 $ids = $notice->fetchAll('id');