StatusTransformer.php 2.0 KB

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