From 25f3fa06aff9d731779ae77b36c2b4b6a83024b3 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 8 Mar 2024 03:49:47 -0700 Subject: [PATCH] Update AP Profile Transformer, add `suspended` attribute --- .../ActivityPub/ProfileTransformer.php | 107 +++++++++--------- 1 file changed, 56 insertions(+), 51 deletions(-) diff --git a/app/Transformer/ActivityPub/ProfileTransformer.php b/app/Transformer/ActivityPub/ProfileTransformer.php index 45d22cd11..a8173c4d0 100644 --- a/app/Transformer/ActivityPub/ProfileTransformer.php +++ b/app/Transformer/ActivityPub/ProfileTransformer.php @@ -3,67 +3,72 @@ namespace App\Transformer\ActivityPub; use App\Profile; -use League\Fractal; use App\Services\AccountService; +use League\Fractal; class ProfileTransformer extends Fractal\TransformerAbstract { public function transform(Profile $profile) { $res = [ - '@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', + '@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' - ] - ]; + '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', + ], + ]; - if($profile->aliases->count()) { - $res['alsoKnownAs'] = $profile->aliases->map(fn($alias) => $alias->uri); - } + if ($profile->status === 'delete' || $profile->deleted_at != null) { + $res['suspended'] = true; + } else { + 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']; - } + if ($profile->moved_to_profile_id) { + $res['movedTo'] = AccountService::get($profile->moved_to_profile_id)['url']; + } + } - return $res; + return $res; } }