1
0
Fork 0
forked from mirror/pixelfed

Update AP CreateNote Transformer

This commit is contained in:
Daniel Supernault 2018-11-12 23:48:27 -07:00
parent 3d3f5ff648
commit 86faa0f297
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -9,6 +9,23 @@ class CreateNote extends Fractal\TransformerAbstract
{
public function transform(Status $status)
{
$mentions = $status->mentions->map(function ($mention) {
return [
'type' => 'Mention',
'href' => $mention->permalink(),
'name' => $mention->emailUrl()
];
})->toArray();
$hashtags = $status->hashtags->map(function ($hashtag) {
return [
'type' => 'Hashtag',
'href' => $hashtag->url(),
'name' => "#{$hashtag->name}",
];
})->toArray();
$tags = array_merge($mentions, $hashtags);
return [
'@context' => [
'https://www.w3.org/ns/activitystreams',
@ -28,27 +45,15 @@ class CreateNote extends Fractal\TransformerAbstract
'cc' => $status->scopeToAudience('cc'),
'object' => [
'id' => $status->url(),
// TODO: handle other types
'type' => 'Note',
// XXX: CW Title
'summary' => null,
'content' => $status->rendered ?? $status->caption,
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
// TODO: fix date format
'published' => $status->created_at->toAtomString(),
'url' => $status->url(),
'attributedTo' => $status->profile->permalink(),
'to' => [
// TODO: handle proper scope
'https://www.w3.org/ns/activitystreams#Public',
],
'cc' => [
// TODO: add cc's
$status->profile->permalink('/followers'),
],
'to' => $status->scopeToAudience('to'),
'cc' => $status->scopeToAudience('cc'),
'sensitive' => (bool) $status->is_nsfw,
'attachment' => $status->media->map(function ($media) {
return [
@ -58,7 +63,7 @@ class CreateNote extends Fractal\TransformerAbstract
'name' => null,
];
})->toArray(),
'tag' => [],
'tag' => $tags,
]
];
}