function _streamDirect($user_id, $offset = 0, $limit = NOTICES_PER_PAGE, $since_id = 0, $max_id = 0) { $reply = new Reply(); $reply->profile_id = $user_id; if ($since_id != 0) { $reply->whereAdd('notice_id > ' . $since_id); } if ($max_id != 0) { $reply->whereAdd('notice_id <= ' . $max_id); } $reply->orderBy('notice_id DESC'); if (!is_null($offset)) { $reply->limit($offset, $limit); } $ids = array(); if ($reply->find()) { while ($reply->fetch()) { $ids[] = $reply->notice_id; } } return $ids; }
function clearReplies() { $replyNotice = new Notice(); $replyNotice->reply_to = $this->id; //Null any notices that are replies to this notice if ($replyNotice->find()) { while ($replyNotice->fetch()) { $orig = clone $replyNotice; $replyNotice->reply_to = null; $replyNotice->update($orig); } } // Reply records $reply = new Reply(); $reply->notice_id = $this->id; if ($reply->find()) { while ($reply->fetch()) { self::blow('reply:stream:%d', $reply->profile_id); $reply->delete(); } } $reply->free(); }
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; }
function onHandleQueuedNotice($notice) { $paths = array(); // Add to the author's timeline $user = User::staticGet('id', $notice->profile_id); if (!empty($user)) { $paths[] = array('showstream', $user->nickname); } // Add to the public timeline if ($notice->is_local == Notice::LOCAL_PUBLIC || $notice->is_local == Notice::REMOTE_OMB && !common_config('public', 'localonly')) { $paths[] = array('public'); } // Add to the tags timeline $tags = $this->getNoticeTags($notice); if (!empty($tags)) { foreach ($tags as $tag) { $paths[] = array('tag', $tag); } } // Add to inbox timelines // XXX: do a join $ni = $notice->whoGets(); foreach (array_keys($ni) as $user_id) { $user = User::staticGet('id', $user_id); $paths[] = array('all', $user->nickname); } // Add to the replies timeline $reply = new Reply(); $reply->notice_id = $notice->id; if ($reply->find()) { while ($reply->fetch()) { $user = User::staticGet('id', $reply->profile_id); if (!empty($user)) { $paths[] = array('replies', $user->nickname); } } } // 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::staticGet('id', $gi->group_id); $paths[] = array('showgroup', $ug->nickname); } } if (count($paths) > 0) { $json = $this->noticeAsJson($notice); $this->_connect(); foreach ($paths as $path) { $timeline = $this->_pathToChannel($path); $this->_publish($timeline, $json); } $this->_disconnect(); } return true; }
function blowRepliesCache($blowLast = false) { $cache = common_memcache(); if ($cache) { $reply = new Reply(); $reply->notice_id = $this->id; if ($reply->find()) { while ($reply->fetch()) { $cache->delete(common_cache_key('user:replies:' . $reply->profile_id)); if ($blowLast) { $cache->delete(common_cache_key('user:replies:' . $reply->profile_id . ';last')); } } } $reply->free(); unset($reply); } }