2018-05-20 03:18:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Transformer\ActivityPub;
|
|
|
|
|
|
|
|
use App\Profile;
|
2023-08-08 05:59:10 +00:00
|
|
|
use App\Services\AccountService;
|
2024-03-08 10:49:47 +00:00
|
|
|
use League\Fractal;
|
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 = [
|
2024-03-08 10:49:47 +00:00
|
|
|
'@context' => [
|
|
|
|
'https://w3id.org/security/v1',
|
|
|
|
'https://www.w3.org/ns/activitystreams',
|
|
|
|
[
|
|
|
|
'toot' => 'http://joinmastodon.org/ns#',
|
|
|
|
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
|
|
|
|
'alsoKnownAs' => [
|
|
|
|
'@id' => 'as:alsoKnownAs',
|
|
|
|
'@type' => '@id',
|
|
|
|
],
|
|
|
|
'movedTo' => [
|
|
|
|
'@id' => 'as:movedTo',
|
|
|
|
'@type' => '@id',
|
|
|
|
],
|
|
|
|
'indexable' => 'toot:indexable',
|
|
|
|
'suspended' => 'toot:suspended',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'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(),
|
|
|
|
'manuallyApprovesFollowers' => (bool) $profile->is_private,
|
|
|
|
'indexable' => (bool) $profile->indexable,
|
|
|
|
'published' => $profile->created_at->format('Y-m-d').'T00:00:00Z',
|
|
|
|
'publicKey' => [
|
|
|
|
'id' => $profile->permalink().'#main-key',
|
|
|
|
'owner' => $profile->permalink(),
|
|
|
|
'publicKeyPem' => $profile->public_key,
|
|
|
|
],
|
|
|
|
'icon' => [
|
|
|
|
'type' => 'Image',
|
|
|
|
'mediaType' => 'image/jpeg',
|
|
|
|
'url' => $profile->avatarUrl(),
|
|
|
|
],
|
|
|
|
'endpoints' => [
|
|
|
|
'sharedInbox' => config('app.url').'/f/inbox',
|
2018-08-28 03:07:36 +00:00
|
|
|
],
|
2024-03-08 10:49:47 +00:00
|
|
|
];
|
2023-08-08 05:59:10 +00:00
|
|
|
|
2024-03-08 10:49:47 +00:00
|
|
|
if ($profile->status === 'delete' || $profile->deleted_at != null) {
|
|
|
|
$res['suspended'] = true;
|
2024-03-08 11:24:13 +00:00
|
|
|
$res['name'] = '';
|
|
|
|
unset($res['icon']);
|
|
|
|
$res['summary'] = '';
|
|
|
|
$res['indexable'] = false;
|
|
|
|
$res['manuallyApprovesFollowers'] = false;
|
2024-03-08 10:49:47 +00:00
|
|
|
} else {
|
|
|
|
if ($profile->aliases->count()) {
|
|
|
|
$res['alsoKnownAs'] = $profile->aliases->map(fn ($alias) => $alias->uri);
|
|
|
|
}
|
2023-08-08 05:59:10 +00:00
|
|
|
|
2024-03-08 10:49:47 +00:00
|
|
|
if ($profile->moved_to_profile_id) {
|
2024-03-08 10:56:53 +00:00
|
|
|
$movedTo = AccountService::get($profile->moved_to_profile_id);
|
|
|
|
if ($movedTo && isset($movedTo['url'], $movedTo['id'])) {
|
|
|
|
$res['movedTo'] = $movedTo['url'];
|
|
|
|
}
|
2024-03-08 10:49:47 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-08 05:59:10 +00:00
|
|
|
|
2024-03-08 10:49:47 +00:00
|
|
|
return $res;
|
2018-08-28 03:07:36 +00:00
|
|
|
}
|
|
|
|
}
|