From 7c80f513d57939ff5fc1bd97f285c845c5363999 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 29 Apr 2021 20:22:38 +0000 Subject: [PATCH] Transmit shared attachments via ActivityPub --- src/Protocol/ActivityPub/Transmitter.php | 33 +++++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 2c1276c7e7..1fd493ccf3 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -1291,22 +1291,35 @@ class Transmitter $attachments[] = $attachment; } */ - foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) { - $attachments[] = ['type' => 'Document', - 'mediaType' => $attachment['mimetype'], - 'url' => $attachment['url'], - 'name' => $attachment['description']]; + $uriids = [$item['uri-id']]; + $shared = BBCode::fetchShareAttributes($item['body']); + if (!empty($shared['guid'])) { + $shared_item = Post::selectFirst(['uri-id'], ['guid' => $shared['guid']]); + if (!empty($shared_item['uri-id'])) { + $uriids[] = $shared_item['uri-id']; + } + } + + foreach ($uriids as $uriid) { + foreach (Post\Media::getByURIId($uriid, [Post\Media::DOCUMENT, Post\Media::TORRENT, Post\Media::UNKNOWN]) as $attachment) { + $attachments[] = ['type' => 'Document', + 'mediaType' => $attachment['mimetype'], + 'url' => $attachment['url'], + 'name' => $attachment['description']]; + } } if ($type != 'Note') { return $attachments; } - foreach (Post\Media::getByURIId($item['uri-id'], [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]) as $attachment) { - $attachments[] = ['type' => 'Document', - 'mediaType' => $attachment['mimetype'], - 'url' => $attachment['url'], - 'name' => $attachment['description']]; + foreach ($uriids as $uriid) { + foreach (Post\Media::getByURIId($uriid, [Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]) as $attachment) { + $attachments[] = ['type' => 'Document', + 'mediaType' => $attachment['mimetype'], + 'url' => $attachment['url'], + 'name' => $attachment['description']]; + } } return $attachments;