]> git.mxchange.org Git - friendica.git/commitdiff
Merge pull request #7184 from annando/add-tag
authorPhilipp <admin+Github@philipp.info>
Sun, 26 May 2019 06:14:18 +0000 (08:14 +0200)
committerGitHub <noreply@github.com>
Sun, 26 May 2019 06:14:18 +0000 (08:14 +0200)
AP: We now transmit "add tag" activity

1  2 
src/Protocol/ActivityPub/Transmitter.php

index ed792db16e75a85952bf5a1eb4bcc2da80ad2241,1a2c13533070440dbec2d5a7fd8e95102fe82cc7..06dbaee71f81f1c619a9e857dde8dd80c465cb01
@@@ -21,6 -21,7 +21,7 @@@ use Friendica\Model\User
  use Friendica\Util\DateTimeFormat;
  use Friendica\Content\Text\BBCode;
  use Friendica\Content\Text\Plaintext;
+ use Friendica\Util\XML;
  use Friendica\Util\JsonLD;
  use Friendica\Util\LDSignature;
  use Friendica\Model\Profile;
@@@ -772,6 -773,8 +773,8 @@@ class Transmitte
                        $type = 'TentativeAccept';
                } elseif ($item['verb'] == ACTIVITY_FOLLOW) {
                        $type = 'Follow';
+               } elseif ($item['verb'] == ACTIVITY_TAG) {
+                       $type = 'Add';
                } else {
                        $type = '';
                }
  
                if (in_array($data['type'], ['Create', 'Update', 'Delete'])) {
                        $data['object'] = self::createNote($item);
+               } elseif ($data['type'] == 'Add') {
+                       $data = self::createAddTag($item, $data);
                } elseif ($data['type'] == 'Announce') {
                        $data = self::createAnnounce($item, $data);
                } elseif ($data['type'] == 'Follow') {
                return $data;
        }
  
+       /**
+        * Creates an an "add tag" entry
+        *
+        * @param array $item
+        * @param array $data activity data
+        *
+        * @return array with activity data for adding tags
+        * @throws \Friendica\Network\HTTPException\InternalServerErrorException
+        * @throws \ImagickException
+        */
+       private static function createAddTag($item, $data)
+       {
+               $object = XML::parseString($item['object'], false);
+               $target = XML::parseString($item["target"], false);
+               $data['diaspora:guid'] = $item['guid'];
+               $data['actor'] = $item['author-link'];
+               $data['target'] = (string)$target->id;
+               $data['summary'] = BBCode::toPlaintext($item['body']);
+               $data['object'] = ['id' => (string)$object->id, 'type' => 'tag', 'name' => (string)$object->title, 'content' => (string)$object->content];
+               return $data;
+       }
        /**
         * Creates an announce object entry
         *
                        'id' => System::baseUrl() . '/activity/' . System::createGUID(),
                        'type' => 'Accept',
                        'actor' => $owner['url'],
 -                      'object' => ['id' => $id, 'type' => 'Follow',
 +                      'object' => [
 +                              'id' => (string)$id,
 +                              'type' => 'Follow',
                                'actor' => $profile['url'],
 -                              'object' => $owner['url']],
 +                              'object' => $owner['url']
 +                      ],
                        'instrument' => self::getService(),
                        'to' => [$profile['url']]];
  
 -              Logger::log('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG);
 +              Logger::debug('Sending accept to ' . $target . ' for user ' . $uid . ' with id ' . $id);
  
                $signed = LDSignature::sign($data, $owner);
                HTTPSignature::transmit($signed, $profile['inbox'], $uid);
                        'id' => System::baseUrl() . '/activity/' . System::createGUID(),
                        'type' => 'Reject',
                        'actor' => $owner['url'],
 -                      'object' => ['id' => $id, 'type' => 'Follow',
 +                      'object' => [
 +                              'id' => (string)$id,
 +                              'type' => 'Follow',
                                'actor' => $profile['url'],
 -                              'object' => $owner['url']],
 +                              'object' => $owner['url']
 +                      ],
                        'instrument' => self::getService(),
                        'to' => [$profile['url']]];
  
 -              Logger::log('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id, Logger::DEBUG);
 +              Logger::debug('Sending reject to ' . $target . ' for user ' . $uid . ' with id ' . $id);
  
                $signed = LDSignature::sign($data, $owner);
                HTTPSignature::transmit($signed, $profile['inbox'], $uid);