public function onHandleQueuedNotice(Notice $notice) { $paths = array(); // Add to the author's timeline try { $profile = $notice->getProfile(); } catch (Exception $e) { $this->log(LOG_ERR, $e->getMessage()); return true; } try { $user = $profile->getUser(); $paths[] = array('showstream', $user->nickname, null); } catch (NoSuchUserException $e) { // We really should handle the remote profile views too $user = null; } // Add to the public timeline $is_local = intval($notice->is_local); if ($is_local === Notice::LOCAL_PUBLIC || $is_local === Notice::REMOTE && !common_config('public', 'localonly')) { $paths[] = array('public', null, null); } // Add to the tags timeline $tags = $this->getNoticeTags($notice); if (!empty($tags)) { foreach ($tags as $tag) { $paths[] = array('tag', $tag, null); } } // Add to inbox timelines // XXX: do a join $ni = $notice->whoGets(); foreach (array_keys($ni) as $user_id) { $user = User::getKV('id', $user_id); $paths[] = array('all', $user->nickname, null); } // Add to the replies timeline $reply = new Reply(); $reply->notice_id = $notice->id; if ($reply->find()) { while ($reply->fetch()) { $user = User::getKV('id', $reply->profile_id); if (!empty($user)) { $paths[] = array('replies', $user->nickname, null); } } } // Add to the group timeline // XXX: join $gi = new Group_inbox(); $gi->notice_id = $notice->id; if ($gi->find()) { while ($gi->fetch()) { $ug = User_group::getKV('id', $gi->group_id); $paths[] = array('showgroup', $ug->nickname, null); } } if (count($paths) > 0) { $json = $this->noticeAsJson($notice); $this->_connect(); // XXX: We should probably fan-out here and do a // new queue item for each path foreach ($paths as $path) { list($action, $arg1, $arg2) = $path; $channels = Realtime_channel::getAllChannels($action, $arg1, $arg2); $this->log(LOG_INFO, sprintf(_("%d candidate channels for notice %d"), count($channels), $notice->id)); foreach ($channels as $channel) { // XXX: We should probably fan-out here and do a // new queue item for each user/path combo if (is_null($channel->user_id)) { $profile = null; } else { $profile = Profile::getKV('id', $channel->user_id); } if ($notice->inScope($profile)) { $this->log(LOG_INFO, sprintf(_("Delivering notice %d to channel (%s, %s, %s) for user '%s'"), $notice->id, $channel->action, $channel->arg1, $channel->arg2, $profile ? $profile->nickname : "<public>")); $timeline = $this->_pathToChannel(array($channel->channel_key)); $this->_publish($timeline, $json); } } } $this->_disconnect(); } return true; }