2018-05-20 03:18:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Transformer\ActivityPub;
|
|
|
|
|
|
|
|
use App\Profile;
|
|
|
|
use League\Fractal;
|
2023-08-08 05:59:10 +00:00
|
|
|
use App\Services\AccountService;
|
2018-05-20 03:18:06 +00:00
|
|
|
|
|
|
|
class ProfileTransformer extends Fractal\TransformerAbstract
|
|
|
|
{
|
2018-08-28 03:07:36 +00:00
|
|
|
public function transform(Profile $profile)
|
|
|
|
{
|
2023-08-08 05:59:10 +00:00
|
|
|
$res = [
|
2018-08-14 00:18:20 +00:00
|
|
|
'@context' => [
|
|
|
|
'https://w3id.org/security/v1',
|
2022-05-14 15:31:47 +00:00
|
|
|
'https://www.w3.org/ns/activitystreams',
|
2018-08-14 00:18:20 +00:00
|
|
|
[
|
2023-08-28 03:43:11 +00:00
|
|
|
'toot' => 'http://joinmastodon.org/ns#',
|
2023-08-25 05:54:08 +00:00
|
|
|
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
2023-08-08 05:59:10 +00:00
|
|
|
'alsoKnownAs' => [
|
|
|
|
'@id' => 'as:alsoKnownAs',
|
|
|
|
'@type' => '@id'
|
|
|
|
],
|
|
|
|
'movedTo' => [
|
|
|
|
'@id' => 'as:movedTo',
|
|
|
|
'@type' => '@id'
|
2023-08-25 05:31:33 +00:00
|
|
|
],
|
2023-08-28 03:43:11 +00:00
|
|
|
'indexable' => 'toot:indexable',
|
2018-08-28 03:07:36 +00:00
|
|
|
],
|
2018-08-14 00:18:20 +00:00
|
|
|
],
|
2018-08-28 03:07:36 +00:00
|
|
|
'id' => $profile->permalink(),
|
|
|
|
'type' => 'Person',
|
|
|
|
'following' => $profile->permalink('/following'),
|
|
|
|
'followers' => $profile->permalink('/followers'),
|
|
|
|
'inbox' => $profile->permalink('/inbox'),
|
|
|
|
'outbox' => $profile->permalink('/outbox'),
|
|
|
|
'preferredUsername' => $profile->username,
|
|
|
|
'name' => $profile->name,
|
|
|
|
'summary' => $profile->bio,
|
|
|
|
'url' => $profile->url(),
|
2018-08-14 00:18:20 +00:00
|
|
|
'manuallyApprovesFollowers' => (bool) $profile->is_private,
|
2023-08-25 05:31:33 +00:00
|
|
|
'indexable' => (bool) $profile->indexable,
|
2023-12-25 07:30:05 +00:00
|
|
|
'published' => $profile->created_at->format('Y-m-d') . 'T00:00:00Z',
|
2018-05-20 03:18:06 +00:00
|
|
|
'publicKey' => [
|
2018-08-28 03:07:36 +00:00
|
|
|
'id' => $profile->permalink().'#main-key',
|
|
|
|
'owner' => $profile->permalink(),
|
|
|
|
'publicKeyPem' => $profile->public_key,
|
2018-05-20 03:18:06 +00:00
|
|
|
],
|
2018-08-14 01:31:18 +00:00
|
|
|
'icon' => [
|
2018-08-28 03:07:36 +00:00
|
|
|
'type' => 'Image',
|
2018-08-14 01:31:18 +00:00
|
|
|
'mediaType' => 'image/jpeg',
|
2018-08-28 03:07:36 +00:00
|
|
|
'url' => $profile->avatarUrl(),
|
|
|
|
],
|
2020-11-26 07:39:01 +00:00
|
|
|
'endpoints' => [
|
|
|
|
'sharedInbox' => config('app.url') . '/f/inbox'
|
|
|
|
]
|
2018-05-20 03:18:06 +00:00
|
|
|
];
|
2023-08-08 05:59:10 +00:00
|
|
|
|
|
|
|
if($profile->aliases->count()) {
|
|
|
|
$res['alsoKnownAs'] = $profile->aliases->map(fn($alias) => $alias->uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($profile->moved_to_profile_id) {
|
|
|
|
$res['movedTo'] = AccountService::get($profile->moved_to_profile_id)['url'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $res;
|
2018-08-28 03:07:36 +00:00
|
|
|
}
|
|
|
|
}
|