1
0
Fork 0
forked from mirror/pixelfed
pixelfed/app/Transformer/ActivityPub/Verb/Note.php

86 lines
2.5 KiB
PHP
Raw Normal View History

2019-01-11 05:33:44 +00:00
<?php
namespace App\Transformer\ActivityPub\Verb;
use App\Status;
use League\Fractal;
2019-10-07 08:36:29 +00:00
use Illuminate\Support\Str;
2019-01-11 05:33:44 +00:00
class Note extends Fractal\TransformerAbstract
{
public function transform(Status $status)
{
$mentions = $status->mentions->map(function ($mention) {
2019-10-07 08:36:29 +00:00
$webfinger = $mention->emailUrl();
$name = Str::startsWith($webfinger, '@') ?
$webfinger :
'@' . $webfinger;
2019-01-11 05:33:44 +00:00
return [
'type' => 'Mention',
'href' => $mention->permalink(),
2019-10-07 08:36:29 +00:00
'name' => $name
2019-01-11 05:33:44 +00:00
];
})->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',
'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
]
2019-01-11 05:33:44 +00:00
],
'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) {
2019-01-11 05:33:44 +00:00
return [
'type' => $media->activityVerb(),
'mediaType' => $media->mime,
'url' => $media->url(),
2019-03-06 00:34:47 +00:00
'name' => $media->caption,
2019-01-11 05:33:44 +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'
],
'location' => $status->place_id ? [
'type' => 'Place',
'name' => $status->place->name,
'longitude' => $status->place->long,
2019-09-06 01:58:38 +00:00
'latitude' => $status->place->lat,
'country' => $status->place->country
] : null,
2019-01-11 05:33:44 +00:00
];
}
}