]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Qvitter API changes (thanks hannes2peer)
[quix0rs-gnu-social.git] / classes / Notice.php
index f10146300cfc2013821f6c3ca66bc5919ce46a3b..4812dff91a29b5caf70fb9e2262154fcaef43889 100644 (file)
@@ -211,6 +211,11 @@ class Notice extends Managed_DataObject
         return $result;
     }
 
+    public function getUri()
+    {
+        return $this->uri;
+    }
+
     /**
      * Extract #hashtags from this notice's content and save them to the database.
      */
@@ -417,7 +422,7 @@ class Notice extends Managed_DataObject
 
             $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.'));
             }
@@ -439,7 +444,7 @@ class Notice extends Managed_DataObject
                 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.'));
             }
@@ -920,23 +925,26 @@ class Notice extends Managed_DataObject
 
         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;
     }
 
@@ -1302,17 +1310,15 @@ class Notice extends Managed_DataObject
         $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
@@ -1709,9 +1715,9 @@ class Notice extends Managed_DataObject
         // 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)) {
@@ -2532,12 +2538,15 @@ class Notice extends Managed_DataObject
 
     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;
     }