Update AP Profile Transformer, add `suspended` attribute

This commit is contained in:
Daniel Supernault 2024-03-08 03:49:47 -07:00
parent 15ad69f76e
commit 25f3fa06af
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1
1 changed files with 56 additions and 51 deletions

View File

@ -3,67 +3,72 @@
namespace App\Transformer\ActivityPub; namespace App\Transformer\ActivityPub;
use App\Profile; use App\Profile;
use League\Fractal;
use App\Services\AccountService; use App\Services\AccountService;
use League\Fractal;
class ProfileTransformer extends Fractal\TransformerAbstract class ProfileTransformer extends Fractal\TransformerAbstract
{ {
public function transform(Profile $profile) public function transform(Profile $profile)
{ {
$res = [ $res = [
'@context' => [ '@context' => [
'https://w3id.org/security/v1', 'https://w3id.org/security/v1',
'https://www.w3.org/ns/activitystreams', 'https://www.w3.org/ns/activitystreams',
[ [
'toot' => 'http://joinmastodon.org/ns#', 'toot' => 'http://joinmastodon.org/ns#',
'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers', 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
'alsoKnownAs' => [ 'alsoKnownAs' => [
'@id' => 'as:alsoKnownAs', '@id' => 'as:alsoKnownAs',
'@type' => '@id' '@type' => '@id',
], ],
'movedTo' => [ 'movedTo' => [
'@id' => 'as:movedTo', '@id' => 'as:movedTo',
'@type' => '@id' '@type' => '@id',
], ],
'indexable' => 'toot:indexable', 'indexable' => 'toot:indexable',
'suspended' => 'toot:suspended',
],
], ],
], 'id' => $profile->permalink(),
'id' => $profile->permalink(), 'type' => 'Person',
'type' => 'Person', 'following' => $profile->permalink('/following'),
'following' => $profile->permalink('/following'), 'followers' => $profile->permalink('/followers'),
'followers' => $profile->permalink('/followers'), 'inbox' => $profile->permalink('/inbox'),
'inbox' => $profile->permalink('/inbox'), 'outbox' => $profile->permalink('/outbox'),
'outbox' => $profile->permalink('/outbox'), 'preferredUsername' => $profile->username,
'preferredUsername' => $profile->username, 'name' => $profile->name,
'name' => $profile->name, 'summary' => $profile->bio,
'summary' => $profile->bio, 'url' => $profile->url(),
'url' => $profile->url(), 'manuallyApprovesFollowers' => (bool) $profile->is_private,
'manuallyApprovesFollowers' => (bool) $profile->is_private, 'indexable' => (bool) $profile->indexable,
'indexable' => (bool) $profile->indexable, 'published' => $profile->created_at->format('Y-m-d').'T00:00:00Z',
'published' => $profile->created_at->format('Y-m-d') . 'T00:00:00Z', 'publicKey' => [
'publicKey' => [ 'id' => $profile->permalink().'#main-key',
'id' => $profile->permalink().'#main-key', 'owner' => $profile->permalink(),
'owner' => $profile->permalink(), 'publicKeyPem' => $profile->public_key,
'publicKeyPem' => $profile->public_key, ],
], 'icon' => [
'icon' => [ 'type' => 'Image',
'type' => 'Image', 'mediaType' => 'image/jpeg',
'mediaType' => 'image/jpeg', 'url' => $profile->avatarUrl(),
'url' => $profile->avatarUrl(), ],
], 'endpoints' => [
'endpoints' => [ 'sharedInbox' => config('app.url').'/f/inbox',
'sharedInbox' => config('app.url') . '/f/inbox' ],
] ];
];
if($profile->aliases->count()) { if ($profile->status === 'delete' || $profile->deleted_at != null) {
$res['alsoKnownAs'] = $profile->aliases->map(fn($alias) => $alias->uri); $res['suspended'] = true;
} } else {
if ($profile->aliases->count()) {
$res['alsoKnownAs'] = $profile->aliases->map(fn ($alias) => $alias->uri);
}
if($profile->moved_to_profile_id) { if ($profile->moved_to_profile_id) {
$res['movedTo'] = AccountService::get($profile->moved_to_profile_id)['url']; $res['movedTo'] = AccountService::get($profile->moved_to_profile_id)['url'];
} }
}
return $res; return $res;
} }
} }