]> git.mxchange.org Git - friendica.git/commitdiff
Store Pixelfed's capabilities
authorMichael <heluecht@pirati.ca>
Thu, 21 Dec 2023 00:33:42 +0000 (00:33 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 21 Dec 2023 00:33:42 +0000 (00:33 +0000)
src/Model/Tag.php
src/Protocol/ActivityPub/Processor.php
src/Protocol/ActivityPub/Receiver.php
src/Util/JsonLD.php

index 94ced6869d70838c2d047d3b833a04222cab7687..cb891c706dd6bed31ece4995c3c4f693dd8c544c 100644 (file)
@@ -60,6 +60,10 @@ class Tag
        const AUDIENCE   = 14;
        const ATTRIBUTED = 15;
 
+       const CAN_ANNOUNCE = 20;
+       const CAN_LIKE     = 21;
+       const CAN_REPLY    = 22;
+
        const ACCOUNT             = 1;
        const GENERAL_COLLECTION  = 2;
        const FOLLOWER_COLLECTION = 3;
index f42fa245d2f64da19c898615ef1883c74a28267f..2a70e40289fb3f841c81479cf3c72e0c83158369 100644 (file)
@@ -918,6 +918,8 @@ class Processor
 
                self::storeReceivers($item['uri-id'], $activity['receiver_urls'] ?? []);
 
+               self::storeCapabilities($item['uri-id'], $activity['capabilities'] ?? []);
+
                $item['location'] = $activity['location'];
 
                if (!empty($activity['latitude']) && !empty($activity['longitude'])) {
@@ -1343,6 +1345,29 @@ class Processor
                }
        }
 
+       private static function storeCapabilities(int $uriid, array $capabilities)
+       {
+               foreach (['pixelfed:canAnnounce' => Tag::CAN_ANNOUNCE, 'pixelfed:canLike' => Tag::CAN_LIKE, 'pixelfed:canReply' => Tag::CAN_REPLY] as $element => $type) {
+                       if (!empty($capabilities[$element])) {
+                               foreach ($capabilities[$element] as $capability) {
+                                       if ($capability == ActivityPub::PUBLIC_COLLECTION) {
+                                               $name = Receiver::PUBLIC_COLLECTION;
+                                       } elseif (empty($capability) || ($capability == '[]')) {
+                                               continue;
+                                       } elseif ($path = parse_url($capability, PHP_URL_PATH)) {
+                                               $name = trim($path, '/');
+                                       } elseif ($host = parse_url($capability, PHP_URL_HOST)) {
+                                               $name = $host;
+                                       } else {
+                                               Logger::warning('Unable to coerce name from capability', ['element' => $element, 'type' => $type, 'capability' => $capability]);
+                                               $name = '';
+                                       }
+                                       Tag::store($uriid, $type, $name, $capability);
+                               }
+                       }
+               }
+       }
+
        /**
         * Creates an mail post
         *
index ff78f0db82dbe0b574c5e33115a1f80dacff5256..7e8ba6fe014ba240d015811a732e0acbfc286f86 100644 (file)
@@ -1943,6 +1943,10 @@ class Receiver
                $object_data['receiver']       = $receivers;
                $object_data['reception_type'] = $reception_types;
 
+               if (!empty($object['pixelfed:capabilities'])) {
+                       $object_data['capabilities'] = self::getCapabilities($object);
+               }
+
                $object_data['unlisted'] = in_array(-1, $object_data['receiver']);
                unset($object_data['receiver'][-1]);
                unset($object_data['reception_type'][-1]);
@@ -1950,6 +1954,18 @@ class Receiver
                return $object_data;
        }
 
+       private static function getCapabilities($object) {
+               $capabilities = [];
+               foreach (['pixelfed:canAnnounce', 'pixelfed:canLike', 'pixelfed:canReply'] as $element) {
+                       $capabilities_list = JsonLD::fetchElementArray($object['pixelfed:capabilities'], $element, '@id');
+                       if (empty($capabilities_list)) {
+                               continue;
+                       }
+                       $capabilities[$element] = $capabilities_list;
+               }
+               return $capabilities;
+       }
+
        /**
         * Create an object data array from a given activity
         *
index aa83d938a4f71cb248469dd120960362c382ea85..5bf6593aed447fca5a4b9d739ba061c5124911e9 100644 (file)
@@ -171,6 +171,7 @@ class JsonLD
                        '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'],
+                       'pixelfed' => (object)['@id' => 'http://pixelfed.org/ns#', '@type' => '@id'],
                ];
 
                $orig_json = $json;