forked from mirror/pixelfed
Update AP CreateNote Transformer
This commit is contained in:
parent
3d3f5ff648
commit
86faa0f297
1 changed files with 58 additions and 53 deletions
|
@ -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,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue