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);
43 function pushUser($notice)
45 // See if there's any PuSH subscriptions, including OStatus clients.
46 // @fixme handle group subscriptions as well
47 // http://identi.ca/api/statuses/user_timeline/1.atom
48 $feed = common_local_url('ApiTimelineUser',
49 array('id' => $notice->profile_id,
54 $atom = $this->userFeedForNotice($notice);
55 $this->pushFeeds($atom, $sub);
57 common_log(LOG_INFO, "No PuSH subscribers for $feed");
61 function pushGroup($notice, $group_id)
63 $feed = common_local_url('ApiTimelineGroup',
64 array('id' => $group_id,
69 common_log(LOG_INFO, "Building PuSH feed for $feed");
70 $atom = $this->groupFeedForNotice($group_id, $notice);
71 $this->pushFeeds($atom, $sub);
73 common_log(LOG_INFO, "No PuSH subscribers for $feed");
78 function pushFeeds($atom, $sub)
80 common_log(LOG_INFO, "Preparing $sub->N PuSH distribution(s) for $sub->topic");
81 $qm = QueueManager::get();
82 while ($sub->fetch()) {
83 common_log(LOG_INFO, "Prepping PuSH distribution to $sub->callback for $sub->topic");
84 $data = array('sub' => clone($sub),
86 $qm->enqueue($data, 'hubout');
91 * Build a single-item version of the sending user's Atom feed.
92 * @param Notice $notice
95 function userFeedForNotice($notice)
97 // @fixme this feels VERY hacky...
98 // should probably be a cleaner way to do it
101 $api = new ApiTimelineUserAction();
102 $api->prepare(array('id' => $notice->profile_id,
104 'max_id' => $notice->id,
105 'since_id' => $notice->id - 1));
106 $api->showTimeline();
107 $feed = ob_get_clean();
109 // ...and override the content-type back to something normal... eww!
110 // hope there's no other headers that got set while we weren't looking.
111 header('Content-Type: text/html; charset=utf-8');
113 common_log(LOG_DEBUG, $feed);
117 function groupFeedForNotice($group_id, $notice)
119 // @fixme this feels VERY hacky...
120 // should probably be a cleaner way to do it
123 $api = new ApiTimelineGroupAction();
124 $args = array('id' => $group_id,
126 'max_id' => $notice->id,
127 'since_id' => $notice->id - 1);
128 $api->prepare($args);
130 $feed = ob_get_clean();
132 // ...and override the content-type back to something normal... eww!
133 // hope there's no other headers that got set while we weren't looking.
134 header('Content-Type: text/html; charset=utf-8');
136 common_log(LOG_DEBUG, $feed);