1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-28 02:36:50 +00:00
pixelfed/app/Transformer/ActivityPub/Verb/Question.php

107 lines
3.1 KiB
PHP
Raw Normal View History

2021-08-05 02:29:21 +00:00
<?php
namespace App\Transformer\ActivityPub\Verb;
use App\Status;
use League\Fractal;
use Illuminate\Support\Str;
class Question extends Fractal\TransformerAbstract
{
public function transform(Status $status)
{
$mentions = $status->mentions->map(function ($mention) {
$webfinger = $mention->emailUrl();
$name = Str::startsWith($webfinger, '@') ?
$webfinger :
'@' . $webfinger;
return [
'type' => 'Mention',
'href' => $mention->permalink(),
'name' => $name
];
})->toArray();
$hashtags = $status->hashtags->map(function ($hashtag) {
return [
'type' => 'Hashtag',
'href' => $hashtag->url(),
'name' => "#{$hashtag->name}",
];
})->toArray();
$tags = array_merge($mentions, $hashtags);
return [
2022-05-14 15:31:47 +00:00
'@context' => [
'https://w3id.org/security/v1',
'https://www.w3.org/ns/activitystreams',
[
'Hashtag' => 'as:Hashtag',
'sensitive' => 'as:sensitive',
2022-05-16 08:26:46 +00:00
'schema' => 'http://schema.org/',
'pixelfed' => 'http://pixelfed.org/ns#',
2022-05-14 15:31:47 +00:00
'commentsEnabled' => [
2022-05-16 08:26:46 +00:00
'@id' => 'pixelfed:commentsEnabled',
2022-05-14 15:31:47 +00:00
'@type' => 'schema:Boolean'
],
'capabilities' => [
2022-05-16 08:26:46 +00:00
'@id' => 'pixelfed:capabilities',
'@container' => '@set'
2022-05-14 15:31:47 +00:00
],
2022-05-16 08:26:46 +00:00
'announce' => [
'@id' => 'pixelfed:canAnnounce',
'@type' => '@id'
2022-05-14 15:31:47 +00:00
],
2022-05-16 08:26:46 +00:00
'like' => [
'@id' => 'pixelfed:canLike',
'@type' => '@id'
2022-05-14 15:31:47 +00:00
],
2022-05-16 08:26:46 +00:00
'reply' => [
'@id' => 'pixelfed:canReply',
'@type' => '@id'
2022-05-14 15:31:47 +00:00
],
'toot' => 'http://joinmastodon.org/ns#',
'Emoji' => 'toot:Emoji'
]
],
'id' => $status->url(),
'type' => 'Question',
'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' => [],
'tag' => $tags,
'commentsEnabled' => (bool) !$status->comments_disabled,
'capabilities' => [
'announce' => 'https://www.w3.org/ns/activitystreams#Public',
'like' => 'https://www.w3.org/ns/activitystreams#Public',
2022-07-27 09:43:35 +00:00
'reply' => $status->comments_disabled == true ? '[]' : 'https://www.w3.org/ns/activitystreams#Public'
2022-05-14 15:31:47 +00:00
],
'location' => $status->place_id ? [
'type' => 'Place',
'name' => $status->place->name,
'longitude' => $status->place->long,
'latitude' => $status->place->lat,
'country' => $status->place->country
] : null,
'endTime' => $status->poll->expires_at->toAtomString(),
'oneOf' => collect($status->poll->poll_options)->map(function($option, $index) use($status) {
return [
'type' => 'Note',
'name' => $option,
'replies' => [
'type' => 'Collection',
'totalItems' => $status->poll->cached_tallies[$index]
2021-08-05 02:29:21 +00:00
]
2022-05-14 15:31:47 +00:00
];
})
];
2021-08-05 02:29:21 +00:00
}
}