pixelfed/app/Transformer/ActivityPub/StatusTransformer.php
2024-11-19 02:53:39 -07:00

63 lines
2 KiB
PHP

<?php
namespace App\Transformer\ActivityPub;
use App\Services\MediaService;
use App\Status;
use App\Util\Lexer\Autolink;
use League\Fractal;
class StatusTransformer extends Fractal\TransformerAbstract
{
public function transform(Status $status)
{
$content = $status->caption ? Autolink::create()->autolink($status->caption) : null;
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->url(),
// TODO: handle other types
'type' => 'Note',
// XXX: CW Title
'summary' => null,
'content' => $content,
'inReplyTo' => 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'),
],
'sensitive' => (bool) $status->is_nsfw,
'atomUri' => $status->url(),
'inReplyToAtomUri' => null,
'attachment' => MediaService::activitypub($status->id),
'tag' => [],
'location' => $status->place_id ? [
'type' => 'Place',
'name' => $status->place->name,
'longitude' => $status->place->long,
'latitude' => $status->place->lat,
'country' => $status->place->country,
] : null,
];
}
}