2019-01-10 22:33:44 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Transformer\ActivityPub\Verb;
|
|
|
|
|
|
|
|
use App\Status;
|
|
|
|
use League\Fractal;
|
2022-01-19 02:21:26 -07:00
|
|
|
use App\Models\CustomEmoji;
|
2019-10-07 02:36:29 -06:00
|
|
|
use Illuminate\Support\Str;
|
2019-01-10 22:33:44 -07:00
|
|
|
|
|
|
|
class Note extends Fractal\TransformerAbstract
|
|
|
|
{
|
|
|
|
public function transform(Status $status)
|
|
|
|
{
|
|
|
|
|
|
|
|
$mentions = $status->mentions->map(function ($mention) {
|
2019-10-07 02:36:29 -06:00
|
|
|
$webfinger = $mention->emailUrl();
|
|
|
|
$name = Str::startsWith($webfinger, '@') ?
|
|
|
|
$webfinger :
|
|
|
|
'@' . $webfinger;
|
2019-01-10 22:33:44 -07:00
|
|
|
return [
|
|
|
|
'type' => 'Mention',
|
|
|
|
'href' => $mention->permalink(),
|
2019-10-07 02:36:29 -06:00
|
|
|
'name' => $name
|
2019-01-10 22:33:44 -07:00
|
|
|
];
|
|
|
|
})->toArray();
|
2019-10-07 03:00:58 -06:00
|
|
|
|
|
|
|
if($status->in_reply_to_id != null) {
|
|
|
|
$parent = $status->parent()->profile;
|
|
|
|
if($parent) {
|
|
|
|
$webfinger = $parent->emailUrl();
|
|
|
|
$name = Str::startsWith($webfinger, '@') ?
|
|
|
|
$webfinger :
|
|
|
|
'@' . $webfinger;
|
|
|
|
$reply = [
|
|
|
|
'type' => 'Mention',
|
|
|
|
'href' => $parent->permalink(),
|
|
|
|
'name' => $name
|
|
|
|
];
|
2021-09-22 20:04:23 -06:00
|
|
|
array_push($mentions, $reply);
|
2019-10-07 03:00:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-10 22:33:44 -07:00
|
|
|
$hashtags = $status->hashtags->map(function ($hashtag) {
|
|
|
|
return [
|
|
|
|
'type' => 'Hashtag',
|
|
|
|
'href' => $hashtag->url(),
|
|
|
|
'name' => "#{$hashtag->name}",
|
|
|
|
];
|
|
|
|
})->toArray();
|
2022-01-19 02:21:26 -07:00
|
|
|
|
|
|
|
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
|
|
|
$emoji = array_merge($emojis, $mentions);
|
|
|
|
$tags = array_merge($emoji, $hashtags);
|
2019-01-10 22:33:44 -07:00
|
|
|
|
|
|
|
return [
|
|
|
|
'@context' => [
|
|
|
|
'https://w3id.org/security/v1',
|
2022-05-14 10:31:47 -05:00
|
|
|
'https://www.w3.org/ns/activitystreams',
|
2019-04-03 21:04:14 -06:00
|
|
|
[
|
|
|
|
'Hashtag' => 'as:Hashtag',
|
|
|
|
'sensitive' => 'as:sensitive',
|
2022-05-16 02:26:46 -06:00
|
|
|
'schema' => 'http://schema.org/',
|
|
|
|
'pixelfed' => 'http://pixelfed.org/ns#',
|
2022-05-14 10:31:47 -05:00
|
|
|
'commentsEnabled' => [
|
2022-05-16 02:26:46 -06:00
|
|
|
'@id' => 'pixelfed:commentsEnabled',
|
2022-05-14 10:31:47 -05:00
|
|
|
'@type' => 'schema:Boolean'
|
|
|
|
],
|
|
|
|
'capabilities' => [
|
2022-05-16 02:26:46 -06:00
|
|
|
'@id' => 'pixelfed:capabilities',
|
|
|
|
'@container' => '@set'
|
2022-05-14 10:31:47 -05:00
|
|
|
],
|
2022-05-16 02:26:46 -06:00
|
|
|
'announce' => [
|
|
|
|
'@id' => 'pixelfed:canAnnounce',
|
|
|
|
'@type' => '@id'
|
2022-05-14 10:31:47 -05:00
|
|
|
],
|
2022-05-16 02:26:46 -06:00
|
|
|
'like' => [
|
|
|
|
'@id' => 'pixelfed:canLike',
|
|
|
|
'@type' => '@id'
|
2022-05-14 10:31:47 -05:00
|
|
|
],
|
2022-05-16 02:26:46 -06:00
|
|
|
'reply' => [
|
|
|
|
'@id' => 'pixelfed:canReply',
|
|
|
|
'@type' => '@id'
|
2022-01-21 01:55:58 -07:00
|
|
|
],
|
|
|
|
'toot' => 'http://joinmastodon.org/ns#',
|
2023-09-26 23:10:20 -06:00
|
|
|
'Emoji' => 'toot:Emoji',
|
|
|
|
'blurhash' => 'toot:blurhash',
|
2019-04-03 21:04:14 -06:00
|
|
|
]
|
2019-01-10 22:33:44 -07:00
|
|
|
],
|
|
|
|
'id' => $status->url(),
|
|
|
|
'type' => 'Note',
|
2022-05-18 02:58:49 -06:00
|
|
|
'summary' => $status->is_nsfw ? $status->cw_summary : null,
|
2019-01-10 22:33:44 -07:00
|
|
|
'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,
|
2019-03-08 23:49:41 -07:00
|
|
|
'attachment' => $status->media()->orderBy('order')->get()->map(function ($media) {
|
2023-09-26 23:10:20 -06:00
|
|
|
$res = [
|
2019-01-10 22:33:44 -07:00
|
|
|
'type' => $media->activityVerb(),
|
|
|
|
'mediaType' => $media->mime,
|
|
|
|
'url' => $media->url(),
|
2019-03-05 17:34:47 -07:00
|
|
|
'name' => $media->caption,
|
2019-01-10 22:33:44 -07:00
|
|
|
];
|
2023-09-26 23:10:20 -06:00
|
|
|
if($media->blurhash) {
|
|
|
|
$res['blurhash'] = $media->blurhash;
|
|
|
|
}
|
|
|
|
if($media->width) {
|
|
|
|
$res['width'] = $media->width;
|
|
|
|
}
|
|
|
|
if($media->height) {
|
|
|
|
$res['height'] = $media->height;
|
|
|
|
}
|
|
|
|
return $res;
|
2019-01-10 22:33:44 -07:00
|
|
|
})->toArray(),
|
|
|
|
'tag' => $tags,
|
2019-04-04 11:53:11 -06:00
|
|
|
'commentsEnabled' => (bool) !$status->comments_disabled,
|
2019-04-09 22:35:49 -06:00
|
|
|
'capabilities' => [
|
|
|
|
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
|
|
|
|
'like' => 'https://www.w3.org/ns/activitystreams#Public',
|
2022-07-27 04:43:35 -05:00
|
|
|
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
|
2019-09-05 18:27:05 -06:00
|
|
|
],
|
|
|
|
'location' => $status->place_id ? [
|
|
|
|
'type' => 'Place',
|
|
|
|
'name' => $status->place->name,
|
|
|
|
'longitude' => $status->place->long,
|
2019-09-05 19:58:38 -06:00
|
|
|
'latitude' => $status->place->lat,
|
2019-09-05 18:27:05 -06:00
|
|
|
'country' => $status->place->country
|
|
|
|
] : null,
|
2019-01-10 22:33:44 -07:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|