StatusTransformer.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Transformer\ActivityPub;
  3. use App\Status;
  4. use League\Fractal;
  5. use App\Services\MediaService;
  6. class StatusTransformer extends Fractal\TransformerAbstract
  7. {
  8. public function transform(Status $status)
  9. {
  10. return [
  11. '@context' => [
  12. 'https://www.w3.org/ns/activitystreams',
  13. 'https://w3id.org/security/v1',
  14. [
  15. 'manuallyApprovesFollowers' => 'as:manuallyApprovesFollowers',
  16. 'featured' => [
  17. 'https://pixelfed.org/ns#featured' => ['@type' => '@id'],
  18. ],
  19. ],
  20. ],
  21. 'id' => $status->url(),
  22. // TODO: handle other types
  23. 'type' => 'Note',
  24. // XXX: CW Title
  25. 'summary' => null,
  26. 'content' => $status->rendered ?? $status->caption,
  27. 'inReplyTo' => null,
  28. // TODO: fix date format
  29. 'published' => $status->created_at->toAtomString(),
  30. 'url' => $status->url(),
  31. 'attributedTo' => $status->profile->permalink(),
  32. 'to' => [
  33. // TODO: handle proper scope
  34. 'https://www.w3.org/ns/activitystreams#Public',
  35. ],
  36. 'cc' => [
  37. // TODO: add cc's
  38. $status->profile->permalink('/followers'),
  39. ],
  40. 'sensitive' => (bool) $status->is_nsfw,
  41. 'atomUri' => $status->url(),
  42. 'inReplyToAtomUri' => null,
  43. 'attachment' => MediaService::activitypub($status->id),
  44. 'tag' => [],
  45. 'location' => $status->place_id ? [
  46. 'type' => 'Place',
  47. 'name' => $status->place->name,
  48. 'longitude' => $status->place->long,
  49. 'latitude' => $status->place->lat,
  50. 'country' => $status->place->country
  51. ] : null,
  52. ];
  53. }
  54. }