function getNoticeIds($offset, $limit, $since_id, $max_id) { $notice = new Notice(); $qry = null; $qry = 'SELECT notice.* FROM notice '; $qry .= 'INNER JOIN happening ON happening.uri = notice.uri '; $qry .= 'AND notice.is_local != ' . Notice::GATEWAY . ' '; if ($since_id != 0) { $qry .= 'AND notice.id > ' . $since_id . ' '; } if ($max_id != 0) { $qry .= 'AND notice.id <= ' . $max_id . ' '; } // NOTE: we sort by event time, not by notice time! $qry .= 'ORDER BY happening.created DESC '; if (!is_null($offset)) { $qry .= "LIMIT {$limit} OFFSET {$offset}"; } $notice->query($qry); $ids = array(); while ($notice->fetch()) { $ids[] = $notice->id; } $notice->free(); unset($notice); return $ids; }
/** * Grab the earliest notice from this conversation. * * @return Notice or null */ function conversationRoot($profile = -1) { // XXX: can this happen? if (empty($this->conversation)) { return null; } // Get the current profile if not specified if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } // If this notice is out of scope, no root for you! if (!$this->inScope($profile)) { return null; } // If this isn't a reply to anything, then it's its own // root if it's the earliest notice in the conversation: if (empty($this->reply_to)) { $root = new Notice(); $root->conversation = $this->conversation; $root->orderBy('notice.created ASC'); $root->find(true); // true means "fetch first result" $root->free(); return $root; } if (is_null($profile)) { $keypart = sprintf('notice:conversation_root:%d:null', $this->id); } else { $keypart = sprintf('notice:conversation_root:%d:%d', $this->id, $profile->id); } $root = self::cacheGet($keypart); if ($root !== false && $root->inScope($profile)) { return $root; } $last = $this; while (true) { try { $parent = $last->getParent(); if ($parent->inScope($profile)) { $last = $parent; continue; } } catch (NoParentNoticeException $e) { // Latest notice has no parent } catch (NoResultException $e) { // Notice was not found, so we can't go further up in the tree. // FIXME: Maybe we should do this in a more stable way where deleted // notices won't break conversation chains? } // No parent, or parent out of scope $root = $last; break; } self::cacheSet($keypart, $root); return $root; }
function _repeatsOfMeDirect($offset, $limit, $since_id, $max_id) { $qry = 'SELECT DISTINCT original.id AS id ' . 'FROM notice original JOIN notice rept ON original.id = rept.repeat_of ' . 'WHERE original.profile_id = ' . $this->id . ' '; if ($since_id != 0) { $qry .= 'AND original.id > ' . $since_id . ' '; } if ($max_id != 0) { $qry .= 'AND original.id <= ' . $max_id . ' '; } // NOTE: we sort by fave time, not by notice time! $qry .= 'ORDER BY original.id DESC '; if (!is_null($offset)) { $qry .= "LIMIT {$limit} OFFSET {$offset}"; } $ids = array(); $notice = new Notice(); $notice->query($qry); while ($notice->fetch()) { $ids[] = $notice->id; } $notice->free(); $notice = NULL; return $ids; }
function _repeatStreamDirect($limit) { $notice = new Notice(); $notice->selectAdd(); // clears it $notice->selectAdd('id'); $notice->repeat_of = $this->id; $notice->orderBy('created'); // NB: asc! if (!is_null($offset)) { $notice->limit($offset, $limit); } $ids = array(); if ($notice->find()) { while ($notice->fetch()) { $ids[] = $notice->id; } } $notice->free(); $notice = NULL; return $ids; }
/** * Grab the earliest notice from this conversation. * * @return Notice or null */ function conversationRoot($profile = -1) { // XXX: can this happen? if (empty($this->conversation)) { return null; } // Get the current profile if not specified if (is_int($profile) && $profile == -1) { $profile = Profile::current(); } // If this notice is out of scope, no root for you! if (!$this->inScope($profile)) { return null; } // If this isn't a reply to anything, then it's its own // root if it's the earliest notice in the conversation: if (empty($this->reply_to)) { $root = new Notice(); $root->conversation = $this->conversation; $root->orderBy('notice.created ASC'); $root->find(); $root->fetch(); $root->free(); return $root; } if (is_null($profile)) { $keypart = sprintf('notice:conversation_root:%d:null', $this->id); } else { $keypart = sprintf('notice:conversation_root:%d:%d', $this->id, $profile->id); } $root = self::cacheGet($keypart); if ($root !== false && $root->inScope($profile)) { return $root; } $last = $this; while (true) { try { $parent = $last->getParent(); if ($parent->inScope($profile)) { $last = $parent; continue; } } catch (NoParentNoticeException $e) { // Latest notice has no parent } // No parent, or parent out of scope $root = $last; break; } self::cacheSet($keypart, $root); return $root; }
function _repeatsOfMeDirect($offset, $limit, $since_id, $max_id) { $qry = 'SELECT DISTINCT original.id AS id ' . 'FROM notice original JOIN notice rept ON original.id = rept.repeat_of ' . 'WHERE original.profile_id = ' . $this->id . ' '; $since = Notice::whereSinceId($since_id, 'original.id', 'original.created'); if ($since) { $qry .= "AND ({$since}) "; } $max = Notice::whereMaxId($max_id, 'original.id', 'original.created'); if ($max) { $qry .= "AND ({$max}) "; } $qry .= 'ORDER BY original.created, original.id DESC '; if (!is_null($offset)) { $qry .= "LIMIT {$limit} OFFSET {$offset}"; } $ids = array(); $notice = new Notice(); $notice->query($qry); while ($notice->fetch()) { $ids[] = $notice->id; } $notice->free(); $notice = NULL; return $ids; }