]> git.mxchange.org Git - friendica.git/commitdiff
Support for quoted links is added
authorMichael <heluecht@pirati.ca>
Thu, 29 Sep 2022 16:04:33 +0000 (16:04 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 29 Sep 2022 16:04:33 +0000 (16:04 +0000)
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php
src/Util/JsonLD.php
static/litepub-0.1.jsonld

index 6fcce4a3aba2baffddf1cd25b4e3e70113507d91..f75e6189b88a08187bdb038ee50b1ffae1c9129f 100644 (file)
@@ -848,6 +848,10 @@ class Processor
                        }
                        $item['content-warning'] = HTML::toBBCode($activity['summary'] ?? '');
                        $item['raw-body'] = $item['body'] = $content;
+
+                       if (!empty($activity['quote-url'])) {
+                               $item['body'] .= self::addSharedData($activity['quote-url']);
+                       }
                }
 
                self::storeFromBody($item);
@@ -866,6 +870,40 @@ class Processor
                return $item;
        }
 
+       /**
+        * Add a share block for the given quote link
+        *
+        * @param string $url
+        * @return string
+        */
+       private static function addSharedData(string $url): string
+       {
+               $id = Item::fetchByLink($url);
+               if (empty($id)) {
+                       return '';
+               }
+
+               $shared_item = Post::selectFirst(['author-name', 'author-link', 'author-avatar', 'plink', 'created', 'guid', 'title', 'body'], ['id' => $id]);
+               if (!DBA::isResult($shared_item)) {
+                       return '';
+               }
+
+               $prefix = BBCode::getShareOpeningTag(
+                       $shared_item['author-name'],
+                       $shared_item['author-link'],
+                       $shared_item['author-avatar'],
+                       $shared_item['plink'],
+                       $shared_item['created'],
+                       $shared_item['guid']
+               );
+
+               if (!empty($shared_item['title'])) {
+                       $prefix .= '[h3]' . $shared_item['title'] . "[/h3]\n";
+               }
+
+               return $prefix . $shared_item['body'] . '[/share]';
+       }
+
        /**
         * Store hashtags and mentions
         *
index c161ce4d114d0a0971a42ec5e04d10f5d13575fb..a410c352589830e483d2bb45349c58926c82a025 100644 (file)
@@ -1916,6 +1916,24 @@ class Receiver
                        $object_data['attachments'] = array_merge($object_data['attachments'], self::processAttachmentUrls($object['as:url'] ?? []));
                }
 
+               // Support for quoted posts (Pleroma, Fedibird and Misskey)
+               $object_data['quote-url'] = JsonLD::fetchElement($object, 'as:quoteUrl', '@value');
+               if (empty($object_data['quote-url'])) {
+                       $object_data['quote-url'] = JsonLD::fetchElement($object, 'fedibird:quoteUri', '@value');
+               }
+               if (empty($object_data['quote-url'])) {
+                       $object_data['quote-url'] = JsonLD::fetchElement($object, 'misskey:_misskey_quote', '@value');
+               }
+
+               // Misskey adds some data to the standard "content" value for quoted posts for backwards compatibility.
+               // Their own "_misskey_content" value does then contain the content without this extra data.
+               if (!empty($object_data['quote-url'])) {
+                       $misskey_content = JsonLD::fetchElement($object, 'misskey:_misskey_content', '@value');
+                       if (!empty($misskey_content)) {
+                               $object_data['content'] = $misskey_content;
+                       }
+               }
+
                // For page types we expect that the alternate url posts to some page.
                // So we add this to the attachments if it differs from the id.
                // Currently only Lemmy is using the page type.
index 947274134ccf91c8c88a5edc5af4fb76ca2835c2..25ce74fcc7c1c044cebc7843f953e361e0a4baac 100644 (file)
@@ -157,6 +157,8 @@ class JsonLD
                        'sc' => (object)['@id' => 'http://schema.org#', '@type' => '@id'],
                        'pt' => (object)['@id' => 'https://joinpeertube.org/ns#', '@type' => '@id'],
                        'mobilizon' => (object)['@id' => 'https://joinmobilizon.org/ns#', '@type' => '@id'],
+                       'fedibird' => (object)['@id' => 'http://fedibird.com/ns#', '@type' => '@id'],
+                       'misskey' => (object)['@id' => 'https://misskey-hub.net/ns#', '@type' => '@id'],
                ];
 
                $orig_json = $json;
index e7722cf726fe2a3b0b3fd3236c04e80808252c38..16c22ff0f6374ab0005c93706c738d0cd0134c5f 100644 (file)
@@ -17,6 +17,7 @@
             "ostatus": "http://ostatus.org#",
             "schema": "http://schema.org#",
             "toot": "http://joinmastodon.org/ns#",
+            "fedibird": "http://fedibird.com/ns#",
             "value": "schema:value",
             "sensitive": "as:sensitive",
             "litepub": "http://litepub.social/ns#",
@@ -26,6 +27,8 @@
                 "@id": "litepub:listMessage",
                 "@type": "@id"
             },
+            "quoteUrl": "as:quoteUrl",
+            "quoteUri": "fedibird:quoteUri",
             "oauthRegistrationEndpoint": {
                 "@id": "litepub:oauthRegistrationEndpoint",
                 "@type": "@id"
@@ -35,7 +38,8 @@
             "alsoKnownAs": {
                 "@id": "as:alsoKnownAs",
                 "@type": "@id"
-            }
+            },
+            "vcard": "http://www.w3.org/2006/vcard/ns#"
         }
     ]
 }