From cb650d9d8ae7c2d38c16a615d39c11afa1b97cfb Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 12 Dec 2018 14:26:00 -0700 Subject: [PATCH] Update AP outbox transformer --- app/Transformer/ActivityPub/ProfileOutbox.php | 73 ++++--------------- 1 file changed, 16 insertions(+), 57 deletions(-) diff --git a/app/Transformer/ActivityPub/ProfileOutbox.php b/app/Transformer/ActivityPub/ProfileOutbox.php index 00e69de95..bd82d9b16 100644 --- a/app/Transformer/ActivityPub/ProfileOutbox.php +++ b/app/Transformer/ActivityPub/ProfileOutbox.php @@ -4,74 +4,33 @@ namespace App\Transformer\ActivityPub; use App\Profile; use League\Fractal; +use App\Transformer\ActivityPub\Verb\CreateNote; class ProfileOutbox extends Fractal\TransformerAbstract { + protected $defaultIncludes = ['orderedItems']; + public function transform(Profile $profile) { - $count = $profile->statuses()->count(); - $statuses = $profile->statuses()->has('media')->orderBy('id', 'desc')->take(20)->get()->map(function ($i, $k) { - $item = [ - 'id' => $i->permalink(), - // TODO: handle other types - 'type' => 'Create', - 'actor' => $i->profile->url(), - 'published' => $i->created_at->toISO8601String(), - 'to' => [ - 'https://www.w3.org/ns/activitystreams#Public', - ], - 'cc' => [ - $i->profile->permalink('/followers'), - ], - 'object' => [ - 'id' => $i->url(), - - // TODO: handle other types - 'type' => 'Note', - - // XXX: CW Title - 'summary' => null, - 'content' => $i->rendered ?? $i->caption, - 'inReplyTo' => null, - - // TODO: fix date format - 'published' => $i->created_at->toAtomString(), - 'url' => $i->url(), - 'attributedTo' => $i->profile->permalink(), - 'to' => [ - // TODO: handle proper scope - 'https://www.w3.org/ns/activitystreams#Public', - ], - 'cc' => [ - // TODO: add cc's - //"{$notice->getProfile()->getUrl()}/subscribers", - ], - 'sensitive' => (bool) $i->is_nsfw, - 'atomUri' => $i->url(), - 'inReplyToAtomUri' => null, - 'attachment' => [ - - // TODO: support more than 1 attachment - [ - 'type' => 'Document', - 'mediaType' => $i->firstMedia()->mime, - 'url' => $i->firstMedia()->url(), - 'name' => null, - ], - ], - 'tag' => [], - ], - ]; - - return $item; - }); + $count = $profile->statuses()->whereHas('media')->count(); return [ '@context' => 'https://www.w3.org/ns/activitystreams', 'id' => $profile->permalink('/outbox'), 'type' => 'OrderedCollection', 'totalItems' => $count, - 'orderedItems' => $statuses, ]; } + + public function includeOrderedItems(Profile $profile) + { + $statuses = $profile + ->statuses() + ->with('media') + ->whereVisibility('public') + ->orderBy('created_at', 'desc') + ->paginate(10); + + return $this->collection($statuses, new CreateNote); + } }