3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2010, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * Send a PuSH subscription verification from our internal hub.
22 * Queue up final distribution for
24 * @author Brion Vibber <brion@status.net>
26 class HubDistribQueueHandler extends QueueHandler
33 function handle($notice)
35 assert($notice instanceof Notice);
37 $this->pushUser($notice);
38 foreach ($notice->getGroups() as $group) {
39 $this->pushGroup($notice, $group->group_id);
44 function pushUser($notice)
46 // See if there's any PuSH subscriptions, including OStatus clients.
47 // @fixme handle group subscriptions as well
48 // http://identi.ca/api/statuses/user_timeline/1.atom
49 $feed = common_local_url('ApiTimelineUser',
50 array('id' => $notice->profile_id,
55 $atom = $this->userFeedForNotice($notice);
56 $this->pushFeeds($atom, $sub);
58 common_log(LOG_INFO, "No PuSH subscribers for $feed");
63 function pushGroup($notice, $group_id)
65 $feed = common_local_url('ApiTimelineGroup',
66 array('id' => $group_id,
71 common_log(LOG_INFO, "Building PuSH feed for $feed");
72 $atom = $this->groupFeedForNotice($group_id, $notice);
73 $this->pushFeeds($atom, $sub);
75 common_log(LOG_INFO, "No PuSH subscribers for $feed");
80 function pushFeeds($atom, $sub)
82 common_log(LOG_INFO, "Preparing $sub->N PuSH distribution(s) for $sub->topic");
83 $qm = QueueManager::get();
84 while ($sub->fetch()) {
85 common_log(LOG_INFO, "Prepping PuSH distribution to $sub->callback for $sub->topic");
86 $data = array('sub' => clone($sub),
88 $qm->enqueue($data, 'hubout');
93 * Build a single-item version of the sending user's Atom feed.
94 * @param Notice $notice
97 function userFeedForNotice($notice)
99 // @fixme this feels VERY hacky...
100 // should probably be a cleaner way to do it
103 $api = new ApiTimelineUserAction();
104 $api->prepare(array('id' => $notice->profile_id,
106 'max_id' => $notice->id,
107 'since_id' => $notice->id - 1));
108 $api->showTimeline();
109 $feed = ob_get_clean();
111 // ...and override the content-type back to something normal... eww!
112 // hope there's no other headers that got set while we weren't looking.
113 header('Content-Type: text/html; charset=utf-8');
115 common_log(LOG_DEBUG, $feed);
119 function groupFeedForNotice($group_id, $notice)
121 // @fixme this feels VERY hacky...
122 // should probably be a cleaner way to do it
125 $api = new ApiTimelineGroupAction();
126 $args = array('id' => $group_id,
128 'max_id' => $notice->id,
129 'since_id' => $notice->id - 1);
130 $api->prepare($args);
132 $feed = ob_get_clean();
134 // ...and override the content-type back to something normal... eww!
135 // hope there's no other headers that got set while we weren't looking.
136 header('Content-Type: text/html; charset=utf-8');
138 common_log(LOG_DEBUG, $feed);