]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/ActivityPub/Receiver.php
Merge pull request #9590 from MrPetovan/bug/fatal-errors
[friendica.git] / src / Protocol / ActivityPub / Receiver.php
index 69d24a7abbc2f5019e1bf8b7df5788f3b06d2df3..af6eb56ceef326e991540aab74a3d1dc41d3fb57 100644 (file)
@@ -99,9 +99,13 @@ class Receiver
                $actor = JsonLD::fetchElement($ldactivity, 'as:actor', '@id');
 
                $apcontact = APContact::getByURL($actor);
-               if (!empty($apcontact) && ($apcontact['type'] == 'Application') && ($apcontact['nick'] == 'relay')) {
+               if (empty($apcontact)) {
+                       Logger::notice('Unable to retrieve AP contact for actor', ['actor' => $actor]);
+               } elseif ($apcontact['type'] == 'Application' && $apcontact['nick'] == 'relay') {
                        self::processRelayPost($ldactivity, $actor);
                        return;
+               } else {
+                       APContact::unmarkForArchival($apcontact);
                }
 
                $http_signer = HTTPSignature::getSigner($body, $header);
@@ -233,6 +237,7 @@ class Receiver
 
                $profile = APContact::getByURL($object_id);
                if (!empty($profile['type'])) {
+                       APContact::unmarkForArchival($profile);
                        return 'as:' . $profile['type'];
                }
 
@@ -1231,24 +1236,36 @@ class Receiver
                        $filetype = strtolower(substr($mediatype, 0, strpos($mediatype, '/')));
 
                        if ($filetype == 'audio') {
-                               $attachments[$filetype] = ['type' => $mediatype, 'url' => $href];
+                               $attachments[$filetype] = ['type' => $mediatype, 'url' => $href, 'height' => null, 'size' => null];
                        } elseif ($filetype == 'video') {
                                $height = (int)JsonLD::fetchElement($url, 'as:height', '@value');
+                               $size = (int)JsonLD::fetchElement($url, 'pt:size', '@value');
 
-                               // We save bandwidth by using a moderate height
+                               // We save bandwidth by using a moderate height (alt least 480 pixel height)
                                // Peertube normally uses these heights: 240, 360, 480, 720, 1080
                                if (!empty($attachments[$filetype]['height']) &&
-                                       (($height > 480) || $height < $attachments[$filetype]['height'])) {
+                                       ($height > $attachments[$filetype]['height']) && ($attachments[$filetype]['height'] >= 480)) {
+                                       continue;
+                               }
+
+                               $attachments[$filetype] = ['type' => $mediatype, 'url' => $href, 'height' => $height, 'size' => $size];
+                       } elseif (in_array($mediatype, ['application/x-bittorrent', 'application/x-bittorrent;x-scheme-handler/magnet'])) {
+                               $height = (int)JsonLD::fetchElement($url, 'as:height', '@value');
+
+                               // For Torrent links we always store the highest resolution
+                               if (!empty($attachments[$mediatype]['height']) && ($height < $attachments[$mediatype]['height'])) {
                                        continue;
                                }
 
-                               $attachments[$filetype] = ['type' => $mediatype, 'url' => $href, 'height' => $height];
+                               $attachments[$mediatype] = ['type' => $mediatype, 'url' => $href, 'height' => $height, 'size' => null];
                        }
                }
 
                foreach ($attachments as $type => $attachment) {
                        $object_data['attachments'][] = ['type' => $type,
                                'mediaType' => $attachment['type'],
+                               'height' => $attachment['height'],
+                               'size' => $attachment['size'],
                                'name' => '',
                                'url' => $attachment['url']];
                }
@@ -1333,7 +1350,7 @@ class Receiver
                $object_data['longitude'] = JsonLD::fetchElement($object_data, 'longitude', '@value');
                $object_data['attachments'] = self::processAttachments(JsonLD::fetchElementArray($object, 'as:attachment') ?? []);
                $object_data['tags'] = self::processTags(JsonLD::fetchElementArray($object, 'as:tag') ?? []);
-               $object_data['emojis'] = self::processEmojis(JsonLD::fetchElementArray($object, 'as:tag', 'toot:Emoji') ?? []);
+               $object_data['emojis'] = self::processEmojis(JsonLD::fetchElementArray($object, 'as:tag', null, '@type', 'toot:Emoji') ?? []);
                $object_data['generator'] = JsonLD::fetchElement($object, 'as:generator', 'as:name', '@type', 'as:Application');
                $object_data['generator'] = JsonLD::fetchElement($object_data, 'generator', '@value');
                $object_data['alternate-url'] = JsonLD::fetchElement($object, 'as:url', '@id');