3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2011, StatusNet, Inc.
6 * Stream of notices for a profile's "all" feed
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @category NoticeStream
23 * @author Evan Prodromou <evan@status.net>
24 * @author Mikael Nordfeldth <mmn@hethane.se>
25 * @author Alexei Sorokin <sor.alexei@meowr.ru>
26 * @copyright 2011 StatusNet, Inc.
27 * @copyright 2014 Free Software Foundation, Inc.
28 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
29 * @link http://status.net/
32 if (!defined('GNUSOCIAL')) {
37 * Stream of notices for a profile's "all" feed
41 * @author Evan Prodromou <evan@status.net>
42 * @author Mikael Nordfeldth <mmn@hethane.se>
43 * @author Alexei Sorokin <sor.alexei@meowr.ru>
44 * @author chimo <chimo@chromic.org>
45 * @copyright 2011 StatusNet, Inc.
46 * @copyright 2014 Free Software Foundation, Inc.
47 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
48 * @link http://status.net/
50 class InboxNoticeStream extends ScopingNoticeStream
55 * @param Profile $target Profile to get a stream for
56 * @param Profile $scoped Currently scoped profile (if null, it is fetched)
58 public function __construct(Profile $target, Profile $scoped = null)
60 parent::__construct(new CachingNoticeStream(new RawInboxNoticeStream($target), 'profileall:'.$target->getID()), $scoped);
65 * Raw stream of notices for the target's inbox
69 * @author Evan Prodromou <evan@status.net>
70 * @author Mikael Nordfeldth <mmn@hethane.se>
71 * @author Alexei Sorokin <sor.alexei@meowr.ru>
72 * @copyright 2011 StatusNet, Inc.
73 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
74 * @link http://status.net/
76 class RawInboxNoticeStream extends FullNoticeStream
78 protected $target = null;
79 protected $inbox = null;
84 * @param Profile $target Profile to get a stream for
86 public function __construct(Profile $target)
88 parent::__construct();
89 $this->target = $target;
95 * @param int $offset Offset from start
96 * @param int $limit Limit of number to get
97 * @param int $since_id Since this notice
98 * @param int $max_id Before this notice
100 * @return array IDs found
102 public function getNoticeIds($offset, $limit, $since_id = null, $max_id = null)
104 $notice = new Notice();
105 $notice->selectAdd();
106 $notice->selectAdd('id');
107 $notice->whereAdd(sprintf('notice.created > "%s"', $notice->escape($this->target->created)));
108 // Reply:: is a table of mentions
109 // Subscription:: is a table of subscriptions (every user is subscribed to themselves)
110 // Sort in descending order as id will give us even really old posts,
111 // which were recently imported. For example, if a remote instance had
112 // problems and just managed to post here.
114 sprintf('id IN (SELECT DISTINCT id FROM (' .
115 '(SELECT id FROM notice WHERE profile_id IN (SELECT subscribed FROM subscription WHERE subscriber = %1$d)) UNION ' .
116 '(SELECT notice_id AS id FROM reply WHERE profile_id = %1$d) UNION ' .
117 '(SELECT notice_id AS id FROM attention WHERE profile_id = %1$d) UNION ' .
118 '(SELECT notice_id AS id FROM group_inbox WHERE group_id IN (SELECT group_id FROM group_member WHERE profile_id = %1$d)) ' .
119 'ORDER BY id DESC) AS T)',
120 $this->target->getID())
123 if (!empty($since_id)) {
124 $notice->whereAdd(sprintf('notice.id > %d', $since_id));
126 if (!empty($max_id)) {
127 $notice->whereAdd(sprintf('notice.id <= %d', $max_id));
130 self::filterVerbs($notice, $this->selectVerbs);
132 $notice->limit($offset, $limit);
134 if (!$notice->find()) {
138 return $notice->fetchAll('id');