From 5559bcdb8fbcd65ece6cdf0795c5a026d0013f76 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 31 May 2018 21:16:43 -0600 Subject: [PATCH] Add ProfileOutbox Transformer --- app/Transformer/ActivityPub/ProfileOutbox.php | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 app/Transformer/ActivityPub/ProfileOutbox.php diff --git a/app/Transformer/ActivityPub/ProfileOutbox.php b/app/Transformer/ActivityPub/ProfileOutbox.php new file mode 100644 index 000000000..9d3b487cb --- /dev/null +++ b/app/Transformer/ActivityPub/ProfileOutbox.php @@ -0,0 +1,79 @@ +statuses()->count(); + $statuses = $profile->statuses()->has('media')->orderBy('id','desc')->take(20)->get()->map(function($i, $k) { + $item = [ + 'id' => $i->url(), + // 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' => null, + 'atomUri' => $i->url(), + 'inReplyToAtomUri' => null, + 'conversation' => $i->url(), + 'attachment' => [ + + // TODO: support more than 1 attachment + [ + 'type' => 'Document', + 'mediaType' => $i->firstMedia()->mime, + 'url' => $i->firstMedia()->url(), + 'name' => null + ] + ], + 'tag' => [] + ] + ]; + return $item; + }); + + return [ + '@context' => 'https://www.w3.org/ns/activitystreams', + 'id' => $profile->permalink('/outbox'), + 'type' => 'OrderedCollection', + 'totalItems' => $count, + 'orderedItems' => $statuses + ]; + } + +} \ No newline at end of file