pixelfed/app/Transformer/ActivityPub/StatusTransformer.php

64 lines
2 KiB
PHP
Raw Normal View History

2018-08-14 04:18:53 +00:00
<?php
namespace App\Transformer\ActivityPub;
2024-11-19 09:53:39 +00:00
use App\Services\MediaService;
2018-08-28 03:07:36 +00:00
use App\Status;
2024-11-19 09:53:39 +00:00
use App\Util\Lexer\Autolink;
2018-08-14 04:18:53 +00:00
use League\Fractal;
class StatusTransformer extends Fractal\TransformerAbstract
{
2018-08-28 03:07:36 +00:00
public function transform(Status $status)
{
$content = $status->caption ? nl2br(Autolink::create()->autolink($status->caption)) : "";
2024-11-19 09:53:39 +00:00
2018-08-28 03:07:36 +00:00
return [
2024-11-19 09:53:39 +00:00
'@context' => [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
[
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
'featured' => [
'https://pixelfed.org/ns#featured' => ['@type' => '@id'],
],
],
2018-08-28 03:07:36 +00:00
],
2024-11-19 09:53:39 +00:00
'id' => $status->url(),
2018-08-14 04:18:53 +00:00
2024-11-19 09:53:39 +00:00
// TODO: handle other types
'type' => 'Note',
2018-08-14 04:18:53 +00:00
2024-11-19 09:53:39 +00:00
// XXX: CW Title
'summary' => null,
'content' => $content,
'inReplyTo' => null,
2018-08-14 04:18:53 +00:00
2024-11-19 09:53:39 +00:00
// 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,
2024-11-19 09:53:39 +00:00
];
2018-08-28 03:07:36 +00:00
}
}