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 // See if there's any PuSH subscriptions, including OStatus clients.
38 // @fixme handle group subscriptions as well
39 // http://identi.ca/api/statuses/user_timeline/1.atom
40 $feed = common_local_url('ApiTimelineUser',
41 array('id' => $notice->profile_id,
46 common_log(LOG_INFO, "Preparing $sub->N PuSH distribution(s) for $feed");
47 $qm = QueueManager::get();
48 $atom = $this->userFeedForNotice($notice);
49 while ($sub->fetch()) {
50 common_log(LOG_INFO, "Prepping PuSH distribution to $sub->callback for $feed");
51 $data = array('sub' => clone($sub),
53 $qm->enqueue($data, 'hubout');
56 common_log(LOG_INFO, "No PuSH subscribers for $feed");
61 * Build a single-item version of the sending user's Atom feed.
62 * @param Notice $notice
65 function userFeedForNotice($notice)
67 // @fixme this feels VERY hacky...
68 // should probably be a cleaner way to do it
71 $api = new ApiTimelineUserAction();
72 $api->prepare(array('id' => $notice->profile_id,
74 'max_id' => $notice->id,
75 'since_id' => $notice->id - 1));
77 $feed = ob_get_clean();
79 // ...and override the content-type back to something normal... eww!
80 // hope there's no other headers that got set while we weren't looking.
81 header('Content-Type: text/html; charset=utf-8');
83 common_log(LOG_DEBUG, $feed);