return $result;
}
+ public function getUri()
+ {
+ return $this->uri;
+ }
+
/**
* Extract #hashtags from this notice's content and save them to the database.
*/
$repeat = Notice::getKV('id', $repeat_of);
- if (empty($repeat)) {
+ if (!($repeat instanceof Notice)) {
// TRANS: Client exception thrown in notice when trying to repeat a missing or deleted notice.
throw new ClientException(_('Cannot repeat; original notice is missing or deleted.'));
}
throw new ClientException(_('Cannot repeat a notice you cannot read.'), 403);
}
- if ($profile->hasRepeated($repeat->id)) {
+ if ($profile->hasRepeated($repeat)) {
// TRANS: Client error displayed when trying to repeat an already repeated notice.
throw new ClientException(_('You already repeated that notice.'));
}
if ($root !== false && $root->inScope($profile)) {
return $root;
- } else {
- $last = $this;
+ }
- do {
+ $last = $this;
+ while (true) {
+ try {
$parent = $last->getParent();
- if (!empty($parent) && $parent->inScope($profile)) {
+ if ($parent->inScope($profile)) {
$last = $parent;
continue;
- } else {
- $root = $last;
- break;
}
- } while (!empty($parent));
-
- self::cacheSet($keypart, $root);
+ } catch (Exception $e) {
+ // Latest notice has no parent
+ }
+ // No parent, or parent out of scope
+ $root = $last;
+ break;
}
+ self::cacheSet($keypart, $root);
+
return $root;
}
$replied = array();
// If it's a reply, save for the replied-to author
-
- if (!empty($this->reply_to)) {
- $original = $this->getParent();
- if (!empty($original)) { // that'd be weird
- $author = $original->getProfile();
- if (!empty($author)) {
- $this->saveReply($author->id);
- $replied[$author->id] = 1;
- self::blow('reply:stream:%d', $author->id);
- }
+ try {
+ $author = $this->getParent()->getProfile();
+ if ($author instanceof Profile) {
+ $this->saveReply($author->id);
+ $replied[$author->id] = 1;
+ self::blow('reply:stream:%d', $author->id);
}
+ } catch (Exception $e) {
+ // Not a reply, since it has no parent!
}
// @todo ideally this parser information would only
// favorite and repeated
if (!empty($cur)) {
- $noticeInfoAttr['favorite'] = ($cur->hasFave($this)) ? "true" : "false";
$cp = $cur->getProfile();
- $noticeInfoAttr['repeated'] = ($cp->hasRepeated($this->id)) ? "true" : "false";
+ $noticeInfoAttr['favorite'] = ($cp->hasFave($this)) ? "true" : "false";
+ $noticeInfoAttr['repeated'] = ($cp->hasRepeated($this)) ? "true" : "false";
}
if (!empty($this->repeat_of)) {
public function getParent()
{
- if (is_int($this->_parent) && $this->_parent == -1) {
- if (empty($this->reply_to)) {
- $this->_parent = null;
- } else {
- $this->_parent = Notice::getKV('id', $this->reply_to);
- }
+ if (empty($this->reply_to)) {
+ // Should this also be NoResultException? I don't think so.
+ throw new Exception('Notice has no parent');
+ } elseif ($this->_parent === -1) { // local object cache
+ $this->_parent = Notice::getKV('id', $this->reply_to);
+ }
+
+ if (!($this->_parent instanceof Notice)) {
+ throw new NoResultException($this->_parent);
}
return $this->_parent;
}