]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Notice.php
Revert some of 8a4bec811b07a0ed9d76d0aceb03855c91a67242
[quix0rs-gnu-social.git] / classes / Notice.php
index a5bd4451ecbfe8aa7c9f620ea74967366f51e98f..a8561948b4d06cc527d243fc7a7d350c7c8c3a41 100644 (file)
@@ -320,6 +320,21 @@ class Notice extends Managed_DataObject
         }
     }
 
+    public function getSelfLink()
+    {
+        if ($this->isLocal()) {
+            return common_local_url('ApiStatusesShow', array('id' => $this->getID(), 'format' => 'atom'));
+        }
+
+        $selfLink = $this->getPref('ostatus', 'self');
+
+        if (!common_valid_http_url($selfLink)) {
+            throw new InvalidUrlException($selfLink);
+        }
+
+        return $selfLink;
+    }
+
     public function getObjectType($canonical=false) {
         if (is_null($this->object_type) || $this->object_type==='') {
             throw new NoObjectTypeException($this);
@@ -442,6 +457,7 @@ class Notice extends Managed_DataObject
     static function saveNew($profile_id, $content, $source, array $options=null) {
         $defaults = array('uri' => null,
                           'url' => null,
+                          'self' => null,
                           'conversation' => null,   // URI of conversation
                           'reply_to' => null,       // This will override convo URI if the parent is known
                           'repeat_of' => null,      // This will override convo URI if the repeated notice is known
@@ -711,6 +727,10 @@ class Notice extends Managed_DataObject
             }
         }
 
+        if ($self && common_valid_http_url($self)) {
+            $notice->setPref('ostatus', 'self', $self);
+        }
+
         // Only save 'attention' and metadata stuff (URLs, tags...) stuff if
         // the activityverb is a POST (since stuff like repeat, favorite etc.
         // reasonably handle notifications themselves.
@@ -770,6 +790,9 @@ class Notice extends Managed_DataObject
             // implied object
             $options['uri'] = $act->id;
             $options['url'] = $act->link;
+            if ($act->selfLink) {
+                $options['self'] = $act->selfLink;
+            }
         } else {
             $actobj = count($act->objects)===1 ? $act->objects[0] : null;
             if (!is_null($actobj) && !empty($actobj->id)) {
@@ -780,6 +803,9 @@ class Notice extends Managed_DataObject
                     $options['url'] = $actobj->id;
                 }
             }
+            if ($actobj->selfLink) {
+                $options['self'] = $actobj->selfLink;
+            }
         }
 
         $defaults = array(
@@ -789,6 +815,7 @@ class Notice extends Managed_DataObject
                           'reply_to' => null,
                           'repeat_of' => null,
                           'scope' => null,
+                          'self' => null,
                           'source' => 'unknown',
                           'tags' => array(),
                           'uri' => null,
@@ -1025,6 +1052,10 @@ class Notice extends Managed_DataObject
             throw new ServerException('Supposedly saved Notice has no ID.');
         }
 
+        if ($self && common_valid_http_url($self)) {
+            $stored->setPref('ostatus', 'self', $self);
+        }
+
         // Only save 'attention' and metadata stuff (URLs, tags...) stuff if
         // the activityverb is a POST (since stuff like repeat, favorite etc.
         // reasonably handle notifications themselves.
@@ -2076,9 +2107,12 @@ class Notice extends Managed_DataObject
                 }
             }
 
+            try {
+                $act->selfLink = $this->getSelfLink();
+            } catch (InvalidUrlException $e) {
+                $act->selfLink = null;
+            }
             if ($this->isLocal()) {
-                $act->selfLink = common_local_url('ApiStatusesShow', array('id' => $this->id,
-                                                                           'format' => 'atom'));
                 $act->editLink = $act->selfLink;
             }
 
@@ -2176,6 +2210,11 @@ class Notice extends Managed_DataObject
             $object->title   = sprintf('New %1$s by %2$s', ActivityObject::canonicalType($object->type), $this->getProfile()->getNickname());
             $object->content = $this->getRendered();
             $object->link    = $this->getUrl();
+            try {
+                $object->selfLink = $this->getSelfLink();
+            } catch (InvalidUrlException $e) {
+                $object->selfLink = null;
+            }
 
             $object->extra[] = array('status_net', array('notice_id' => $this->id));
 
@@ -3201,4 +3240,27 @@ class Notice extends Managed_DataObject
             }
         }
     }
+
+    public function delPref($namespace, $topic) {
+        return Notice_prefs::setData($this, $namespace, $topic, null);
+    }
+
+    public function getPref($namespace, $topic, $default=null) {
+        // If you want an exception to be thrown, call Notice_prefs::getData directly
+        try {
+            return Notice_prefs::getData($this, $namespace, $topic, $default);
+        } catch (NoResultException $e) {
+            return null;
+        }
+    }
+
+    // The same as getPref but will fall back to common_config value for the same namespace/topic
+    public function getConfigPref($namespace, $topic)
+    {
+        return Notice_prefs::getConfigData($this, $namespace, $topic);
+    }
+
+    public function setPref($namespace, $topic, $data) {
+        return Notice_prefs::setData($this, $namespace, $topic, $data);
+    }
 }