1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-24 00:35:59 +00:00
pixelfed/app/Transformer/ActivityPub/ProfileOutbox.php

78 lines
2.3 KiB
PHP
Raw Normal View History

2018-06-01 03:16:43 +00:00
<?php
namespace App\Transformer\ActivityPub;
use App\Profile;
use League\Fractal;
class ProfileOutbox extends Fractal\TransformerAbstract
{
2018-08-28 03:07:36 +00:00
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 = [
2018-08-14 00:17:50 +00:00
'id' => $i->permalink(),
2018-06-01 03:16:43 +00:00
// TODO: handle other types
2018-08-28 03:07:36 +00:00
'type' => 'Create',
'actor' => $i->profile->url(),
2018-06-01 03:16:43 +00:00
'published' => $i->created_at->toISO8601String(),
2018-08-28 03:07:36 +00:00
'to' => [
'https://www.w3.org/ns/activitystreams#Public',
2018-06-01 03:16:43 +00:00
],
'cc' => [
$i->profile->permalink('/followers'),
],
'object' => [
'id' => $i->url(),
// TODO: handle other types
'type' => 'Note',
// XXX: CW Title
2018-08-28 03:07:36 +00:00
'summary' => null,
'content' => $i->rendered ?? $i->caption,
2018-06-01 03:16:43 +00:00
'inReplyTo' => null,
// TODO: fix date format
2018-08-28 03:07:36 +00:00
'published' => $i->created_at->toAtomString(),
'url' => $i->url(),
2018-06-01 03:16:43 +00:00
'attributedTo' => $i->profile->permalink(),
2018-08-28 03:07:36 +00:00
'to' => [
2018-06-01 03:16:43 +00:00
// TODO: handle proper scope
2018-08-28 03:07:36 +00:00
'https://www.w3.org/ns/activitystreams#Public',
2018-06-01 03:16:43 +00:00
],
'cc' => [
// TODO: add cc's
//"{$notice->getProfile()->getUrl()}/subscribers",
],
2018-08-28 03:07:36 +00:00
'sensitive' => (bool) $i->is_nsfw,
'atomUri' => $i->url(),
2018-06-01 03:16:43 +00:00
'inReplyToAtomUri' => null,
2018-08-28 03:07:36 +00:00
'attachment' => [
2018-06-01 03:16:43 +00:00
// TODO: support more than 1 attachment
[
2018-08-28 03:07:36 +00:00
'type' => 'Document',
2018-06-01 03:16:43 +00:00
'mediaType' => $i->firstMedia()->mime,
2018-08-28 03:07:36 +00:00
'url' => $i->firstMedia()->url(),
'name' => null,
],
2018-06-01 03:16:43 +00:00
],
2018-08-28 03:07:36 +00:00
'tag' => [],
],
2018-06-01 03:16:43 +00:00
];
2018-08-28 03:07:36 +00:00
return $item;
});
2018-06-01 03:16:43 +00:00
2018-08-28 03:07:36 +00:00
return [
'@context' => 'https://www.w3.org/ns/activitystreams',
'id' => $profile->permalink('/outbox'),
'type' => 'OrderedCollection',
'totalItems' => $count,
'orderedItems' => $statuses,
];
}
}