]> git.mxchange.org Git - friendica.git/commitdiff
Support for transmitting quoted posts
authorMichael <heluecht@pirati.ca>
Thu, 29 Sep 2022 22:29:15 +0000 (22:29 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 29 Sep 2022 22:29:15 +0000 (22:29 +0000)
src/Protocol/ActivityPub.php
src/Protocol/ActivityPub/Transmitter.php

index 93204e81d3722da96c65810566a4e27e87cf8181..603416a5d2bedb97f9ddb6425a4229589ddcab84 100644 (file)
@@ -72,6 +72,8 @@ class ActivityPub
                'schema' => 'http://schema.org#',
                'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
                'sensitive' => 'as:sensitive', 'Hashtag' => 'as:Hashtag',
+               'quoteUrl' => 'as:quoteUrl',
+               'conversation' => 'ostatus:conversation',
                'directMessage' => 'litepub:directMessage',
                'discoverable' => 'toot:discoverable',
                'PropertyValue' => 'schema:PropertyValue',
index 297020e8ed54b3618ccc5363b25d6341ba7e5ccb..e0d9117e3ea10442df0b00cfad9d5c14b0dfef52 100644 (file)
@@ -1355,11 +1355,12 @@ class Transmitter
        /**
         * Returns a tag array for a given item array
         *
-        * @param array $item Item array
+        * @param array  $item      Item array
+        * @param string $quote_url Url of the attached quote link
         * @return array of tags
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
-       private static function createTagList(array $item): array
+       private static function createTagList(array $item, string $quote_url): array
        {
                $tags = [];
 
@@ -1389,6 +1390,16 @@ class Transmitter
                        $tags[] = ['type' => 'Mention', 'href' => $announce['actor']['url'], 'name' => '@' . $announce['actor']['addr']];
                }
 
+               // @see https://codeberg.org/fediverse/fep/src/branch/main/feps/fep-e232.md
+               if (!empty($quote_url)) {
+                       $tags[] = [
+                               'type'      => 'Link',
+                               'mediaType' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
+                               'href'      => $quote_url,
+                               'name'      => BBCode::convertForUriId($item['uri-id'], $quote_url, BBCode::ACTIVITYPUB)
+                       ];
+               }
+
                return $tags;
        }
 
@@ -1662,6 +1673,12 @@ class Transmitter
 
                        $body = BBCode::setMentionsToNicknames($body);
 
+                       $shared = BBCode::fetchShareAttributes($body);
+                       if (!empty($shared['link']) && !empty($shared['guid']) && !empty($shared['comment'])) {
+                               $body = self::ReplaceSharedData($body);
+                               $data['quoteUrl'] = $shared['link'];
+                       }
+
                        $data['content'] = BBCode::convertForUriId($item['uri-id'], $body, BBCode::ACTIVITYPUB);
                }
 
@@ -1683,7 +1700,7 @@ class Transmitter
                }
 
                $data['attachment'] = self::createAttachmentList($item, $type);
-               $data['tag'] = self::createTagList($item);
+               $data['tag'] = self::createTagList($item, $data['quoteUrl'] ?? '');
 
                if (empty($data['location']) && (!empty($item['coord']) || !empty($item['location']))) {
                        $data['location'] = self::createLocation($item);
@@ -1698,6 +1715,22 @@ class Transmitter
                return $data;
        }
 
+       /**
+        * Replace the share block with a link
+        *
+        * @param string $body
+        * @return string
+        */
+       private static function ReplaceSharedData(string $body): string
+       {
+               return BBCode::convertShare(
+                       $body,
+                       function (array $attributes) {
+                               return $attributes['link'];
+                       }
+               );
+       }
+
        /**
         * Fetches the language from the post, the user or the system.
         *