]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Notices start saving selfLink from activities/objects
authorMikael Nordfeldth <mmn@hethane.se>
Sat, 6 May 2017 10:15:54 +0000 (12:15 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sat, 6 May 2017 10:15:54 +0000 (12:15 +0200)
classes/Notice.php
lib/activity.php
lib/activityhandlerplugin.php
lib/activityutils.php

index a5bd4451ecbfe8aa7c9f620ea74967366f51e98f..28f85ce3fb098aad2795d21d8d4c2355c4d133df 100644 (file)
@@ -59,6 +59,7 @@ class Notice extends Managed_DataObject
     public $content;                         // text
     public $rendered;                        // text
     public $url;                             // varchar(191)   not 255 because utf8mb4 takes more space
+    public $self;                            // varchar(191)   not 255 because utf8mb4 takes more space
     public $created;                         // datetime  multiple_key not_null default_0000-00-00%2000%3A00%3A00
     public $modified;                        // timestamp   not_null default_CURRENT_TIMESTAMP
     public $reply_to;                        // int(4)
@@ -83,6 +84,7 @@ class Notice extends Managed_DataObject
                 'content' => array('type' => 'text', 'description' => 'update content', 'collate' => 'utf8mb4_general_ci'),
                 'rendered' => array('type' => 'text', 'description' => 'HTML version of the content'),
                 'url' => array('type' => 'varchar', 'length' => 191, 'description' => 'URL of any attachment (image, video, bookmark, whatever)'),
+                'self' => array('type' => 'varchar', 'length' => 191, 'description' => 'Resolvable URL to the (remote) Atom entry representation'),
                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
                 'reply_to' => array('type' => 'int', 'description' => 'notice replied to (usually a guess)'),
@@ -442,6 +444,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
@@ -528,6 +531,9 @@ class Notice extends Managed_DataObject
         $notice->source = $source;
         $notice->uri = $uri;
         $notice->url = $url;
+        if ($self && common_valid_http_url($self)) {
+            $notice->self = $self;
+        }
 
         // Get the groups here so we can figure out replies and such
         if (!isset($groups)) {
@@ -770,6 +776,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 +789,9 @@ class Notice extends Managed_DataObject
                     $options['url'] = $actobj->id;
                 }
             }
+            if ($actobj->selfLink) {
+                $options['self'] = $actobj->selfLink;
+            }
         }
 
         $defaults = array(
@@ -789,6 +801,7 @@ class Notice extends Managed_DataObject
                           'reply_to' => null,
                           'repeat_of' => null,
                           'scope' => null,
+                          'self' => null,
                           'source' => 'unknown',
                           'tags' => array(),
                           'uri' => null,
@@ -841,6 +854,9 @@ class Notice extends Managed_DataObject
         $stored->source = $source;
         $stored->uri = $uri;
         $stored->url = $url;
+        if (common_valid_http_url($stored->self)) {
+            $stored->self = $self;
+        }
         $stored->verb = $act->verb;
 
         // we use mb_strlen because it _might_ be that the content is just the string "0"...
index 578a843c32be37e38c31fbf54d7ee59d56da2ba5..a52f29e9ca64e06bdf317f995f4c597acc20559b 100644 (file)
@@ -267,7 +267,7 @@ class Activity
 
         // From APP. Might be useful.
 
-        $this->selfLink = ActivityUtils::getLink($entry, 'self', 'application/atom+xml');
+        $this->selfLink = ActivityUtils::getSelfLink($entry);
         $this->editLink = ActivityUtils::getLink($entry, 'edit', 'application/atom+xml');
     }
 
index afeebb53aae4c53923b7bdb358808fd91c6b307e..0a63bed13bb80a22913630cc0d2056dfc8bf13bf 100644 (file)
@@ -344,6 +344,7 @@ abstract class ActivityHandlerPlugin extends Plugin
 
         $options = array('uri' => $object->id,
                          'url' => $object->link,
+                         'self' => $object->selfLink,
                          'is_local' => Notice::REMOTE,
                          'source' => 'ostatus');
 
@@ -420,6 +421,7 @@ abstract class ActivityHandlerPlugin extends Plugin
 
         $options = array('uri' => $object->id,
                          'url' => $object->link,
+                         'self' => $object->selfLink,
                          'is_local' => Notice::REMOTE,
                          'source' => 'ostatus');
 
@@ -471,6 +473,7 @@ abstract class ActivityHandlerPlugin extends Plugin
 
         $options = array('uri' => $object->id,
                          'url' => $object->link,
+                         'self' => $object->selfLink,
                          'source' => 'restore');
 
         // $user->getProfile() is a Profile
index 58e04e2f76f5846990f4576b89dfb1563864aea3..b83bc0a238045e2acc6959127fba521e199d4fcd 100644 (file)
@@ -65,11 +65,16 @@ class ActivityUtils
      *
      * @return string related link, if any
      */
-    static function getPermalink($element)
+    static function getPermalink(DOMNode $element)
     {
         return self::getLink($element, 'alternate', 'text/html');
     }
 
+    static function getSelfLink(DOMNode $element)
+    {
+        return self::getLink($element, 'self', 'application/atom+xml');
+    }
+
     /**
      * Get the permalink for an Activity object
      *
@@ -90,8 +95,9 @@ class ActivityUtils
                 $linkRel = $link->getAttribute(self::REL);
                 $linkType = $link->getAttribute(self::TYPE);
 
+                // XXX: Am I allowed to do this according to specs? (matching using common_bare_mime)
                 if ($linkRel == $rel &&
-                    (is_null($type) || $linkType == $type)) {
+                    (is_null($type) || common_bare_mime($linkType) == common_bare_mime($type))) {
                     return $link->getAttribute(self::HREF);
                 }
             }