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
|
@ -7,59 +7,64 @@ use League\Fractal;
|
||||||
|
|
||||||
class CreateNote extends Fractal\TransformerAbstract
|
class CreateNote extends Fractal\TransformerAbstract
|
||||||
{
|
{
|
||||||
public function transform(Status $status)
|
public function transform(Status $status)
|
||||||
{
|
{
|
||||||
return [
|
|
||||||
'@context' => [
|
|
||||||
'https://www.w3.org/ns/activitystreams',
|
|
||||||
'https://w3id.org/security/v1',
|
|
||||||
[
|
|
||||||
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
|
||||||
'featured' => [
|
|
||||||
'https://pixelfed.org/ns#featured' => ['@type' => '@id'],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
],
|
|
||||||
'id' => $status->permalink(),
|
|
||||||
'type' => 'Create',
|
|
||||||
'actor' => $status->profile->permalink(),
|
|
||||||
'published' => $status->created_at->toAtomString(),
|
|
||||||
'to' => $status->scopeToAudience('to'),
|
|
||||||
'cc' => $status->scopeToAudience('cc'),
|
|
||||||
'object' => [
|
|
||||||
'id' => $status->url(),
|
|
||||||
|
|
||||||
// TODO: handle other types
|
$mentions = $status->mentions->map(function ($mention) {
|
||||||
'type' => 'Note',
|
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);
|
||||||
|
|
||||||
// XXX: CW Title
|
return [
|
||||||
'summary' => null,
|
'@context' => [
|
||||||
'content' => $status->rendered ?? $status->caption,
|
'https://www.w3.org/ns/activitystreams',
|
||||||
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
'https://w3id.org/security/v1',
|
||||||
|
[
|
||||||
// TODO: fix date format
|
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
||||||
'published' => $status->created_at->toAtomString(),
|
'featured' => [
|
||||||
'url' => $status->url(),
|
'https://pixelfed.org/ns#featured' => ['@type' => '@id'],
|
||||||
'attributedTo' => $status->profile->permalink(),
|
],
|
||||||
'to' => [
|
],
|
||||||
// TODO: handle proper scope
|
],
|
||||||
'https://www.w3.org/ns/activitystreams#Public',
|
'id' => $status->permalink(),
|
||||||
],
|
'type' => 'Create',
|
||||||
'cc' => [
|
'actor' => $status->profile->permalink(),
|
||||||
// TODO: add cc's
|
'published' => $status->created_at->toAtomString(),
|
||||||
$status->profile->permalink('/followers'),
|
'to' => $status->scopeToAudience('to'),
|
||||||
],
|
'cc' => $status->scopeToAudience('cc'),
|
||||||
'sensitive' => (bool) $status->is_nsfw,
|
'object' => [
|
||||||
'attachment' => $status->media->map(function ($media) {
|
'id' => $status->url(),
|
||||||
return [
|
'type' => 'Note',
|
||||||
'type' => 'Document',
|
'summary' => null,
|
||||||
'mediaType' => $media->mime,
|
'content' => $status->rendered ?? $status->caption,
|
||||||
'url' => $media->url(),
|
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
|
||||||
'name' => null,
|
'published' => $status->created_at->toAtomString(),
|
||||||
];
|
'url' => $status->url(),
|
||||||
})->toArray(),
|
'attributedTo' => $status->profile->permalink(),
|
||||||
'tag' => [],
|
'to' => $status->scopeToAudience('to'),
|
||||||
]
|
'cc' => $status->scopeToAudience('cc'),
|
||||||
];
|
'sensitive' => (bool) $status->is_nsfw,
|
||||||
}
|
'attachment' => $status->media->map(function ($media) {
|
||||||
|
return [
|
||||||
|
'type' => 'Document',
|
||||||
|
'mediaType' => $media->mime,
|
||||||
|
'url' => $media->url(),
|
||||||
|
'name' => null,
|
||||||
|
];
|
||||||
|
})->toArray(),
|
||||||
|
'tag' => $tags,
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue