pixelfed/app/Transformer/ActivityPub/Verb/CreateNote.php

82 lines
2.5 KiB
PHP
Raw Normal View History

2018-11-13 06:25:31 +00:00
<?php
namespace App\Transformer\ActivityPub\Verb;
use App\Status;
use League\Fractal;
class CreateNote extends Fractal\TransformerAbstract
{
2018-11-13 06:48:27 +00:00
public function transform(Status $status)
{
2018-11-13 06:25:31 +00:00
2018-11-13 06:48:27 +00:00
$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);
2018-11-13 06:25:31 +00:00
2018-11-13 06:48:27 +00:00
return [
'@context' => [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
2019-04-04 03:04:14 +00:00
[
'sc' => 'http://schema.org#',
2019-04-04 03:04:14 +00:00
'Hashtag' => 'as:Hashtag',
'sensitive' => 'as:sensitive',
'commentsEnabled' => 'sc:Boolean',
'capabilities' => [
'announce' => ['@type' => '@id'],
'like' => ['@type' => '@id'],
'reply' => ['@type' => '@id']
]
2019-04-04 03:04:14 +00:00
]
2018-11-13 06:48:27 +00:00
],
'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(),
'type' => 'Note',
'summary' => null,
'content' => $status->rendered ?? $status->caption,
'inReplyTo' => $status->in_reply_to_id ? $status->parent()->url() : null,
'published' => $status->created_at->toAtomString(),
'url' => $status->url(),
'attributedTo' => $status->profile->permalink(),
'to' => $status->scopeToAudience('to'),
'cc' => $status->scopeToAudience('cc'),
'sensitive' => (bool) $status->is_nsfw,
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
2018-11-13 06:48:27 +00:00
return [
2018-12-12 21:25:27 +00:00
'type' => $media->activityVerb(),
2018-11-13 06:48:27 +00:00
'mediaType' => $media->mime,
'url' => $media->url(),
'name' => $media->caption,
2018-11-13 06:48:27 +00:00
];
})->toArray(),
'tag' => $tags,
'commentsEnabled' => (bool) !$status->comments_disabled,
'capabilities' => [
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
'like' => 'https://www.w3.org/ns/activitystreams#Public',
'reply' => $status->comments_disabled == true ? null : 'https://www.w3.org/ns/activitystreams#Public'
]
2018-11-13 06:48:27 +00:00
]
];
}
2018-11-13 06:25:31 +00:00
}