2018-11-13 06:25:31 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Transformer\ActivityPub\Verb;
|
|
|
|
|
|
|
|
use App\Status;
|
|
|
|
use League\Fractal;
|
2022-01-19 09:21:26 +00:00
|
|
|
use App\Models\CustomEmoji;
|
2019-10-07 08:36:29 +00:00
|
|
|
use Illuminate\Support\Str;
|
2018-11-13 06:25:31 +00:00
|
|
|
|
|
|
|
class CreateNote extends Fractal\TransformerAbstract
|
|
|
|
{
|
2018-11-13 06:48:27 +00:00
|
|
|
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;
|
2018-11-13 06:48:27 +00:00
|
|
|
return [
|
|
|
|
'type' => 'Mention',
|
|
|
|
'href' => $mention->permalink(),
|
2019-10-07 08:36:29 +00:00
|
|
|
'name' => $name
|
2018-11-13 06:48:27 +00:00
|
|
|
];
|
|
|
|
})->toArray();
|
2019-10-07 09:00:58 +00: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
|
|
|
|
];
|
|
|
|
$mentions = array_merge($reply, $mentions);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-13 06:48:27 +00:00
|
|
|
$hashtags = $status->hashtags->map(function ($hashtag) {
|
|
|
|
return [
|
|
|
|
'type' => 'Hashtag',
|
|
|
|
'href' => $hashtag->url(),
|
|
|
|
'name' => "#{$hashtag->name}",
|
|
|
|
];
|
|
|
|
})->toArray();
|
2022-01-19 09:21:26 +00:00
|
|
|
|
|
|
|
$emojis = CustomEmoji::scan($status->caption, true) ?? [];
|
|
|
|
$emoji = array_merge($emojis, $mentions);
|
|
|
|
$tags = array_merge($emoji, $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
|
|
|
[
|
2019-04-04 17:53:11 +00:00
|
|
|
'sc' => 'http://schema.org#',
|
2019-04-04 03:04:14 +00:00
|
|
|
'Hashtag' => 'as:Hashtag',
|
|
|
|
'sensitive' => 'as:sensitive',
|
2019-04-04 17:53:11 +00:00
|
|
|
'commentsEnabled' => 'sc:Boolean',
|
2019-04-10 04:35:49 +00:00
|
|
|
'capabilities' => [
|
|
|
|
'announce' => ['@type' => '@id'],
|
|
|
|
'like' => ['@type' => '@id'],
|
|
|
|
'reply' => ['@type' => '@id']
|
2022-01-21 08:55:58 +00:00
|
|
|
],
|
|
|
|
'toot' => 'http://joinmastodon.org/ns#',
|
|
|
|
'Emoji' => 'toot:Emoji'
|
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,
|
2019-03-09 06:49:41 +00:00
|
|
|
'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(),
|
2019-03-06 00:41:05 +00:00
|
|
|
'name' => $media->caption,
|
2018-11-13 06:48:27 +00:00
|
|
|
];
|
|
|
|
})->toArray(),
|
|
|
|
'tag' => $tags,
|
2019-04-04 17:53:11 +00:00
|
|
|
'commentsEnabled' => (bool) !$status->comments_disabled,
|
2019-04-10 04:35:49 +00:00
|
|
|
'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'
|
2019-09-06 00:27:05 +00:00
|
|
|
],
|
|
|
|
'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,
|
2019-09-06 00:27:05 +00:00
|
|
|
'country' => $status->place->country
|
|
|
|
] : null,
|
2018-11-13 06:48:27 +00:00
|
|
|
]
|
|
|
|
];
|
|
|
|
}
|
2018-11-13 06:25:31 +00:00
|
|
|
}
|