ProfileTransformer.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Transformer\ActivityPub;
  3. use App\Profile;
  4. use League\Fractal;
  5. class ProfileTransformer extends Fractal\TransformerAbstract
  6. {
  7. public function transform(Profile $profile)
  8. {
  9. return [
  10. '@context' => [
  11. 'https://www.w3.org/ns/activitystreams',
  12. 'https://w3id.org/security/v1',
  13. [
  14. 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
  15. 'PropertyValue' => 'schema:PropertyValue',
  16. 'schema' => 'http://schema.org#',
  17. 'value' => 'schema:value'
  18. ],
  19. ],
  20. 'id' => $profile->permalink(),
  21. 'type' => 'Person',
  22. 'following' => $profile->permalink('/following'),
  23. 'followers' => $profile->permalink('/followers'),
  24. 'inbox' => $profile->permalink('/inbox'),
  25. 'outbox' => $profile->permalink('/outbox'),
  26. //'featured' => $profile->permalink('/collections/featured'),
  27. 'preferredUsername' => $profile->username,
  28. 'name' => $profile->name,
  29. 'summary' => $profile->bio,
  30. 'url' => $profile->url(),
  31. 'manuallyApprovesFollowers' => (bool) $profile->is_private,
  32. // 'follower_count' => $profile->followers()->count(),
  33. // 'following_count' => $profile->following()->count(),
  34. 'publicKey' => [
  35. 'id' => $profile->permalink().'#main-key',
  36. 'owner' => $profile->permalink(),
  37. 'publicKeyPem' => $profile->public_key,
  38. ],
  39. 'icon' => [
  40. 'type' => 'Image',
  41. 'mediaType' => 'image/jpeg',
  42. 'url' => $profile->avatarUrl(),
  43. ],
  44. 'endpoints' => [
  45. 'sharedInbox' => config('app.url') . '/f/inbox'
  46. ]
  47. ];
  48. }
  49. }