StatusTransformer.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Transformer\Api\Mastodon\v1;
  3. use App\Status;
  4. use League\Fractal;
  5. use Cache;
  6. use App\Services\MediaService;
  7. use App\Services\ProfileService;
  8. use App\Services\StatusHashtagService;
  9. class StatusTransformer extends Fractal\TransformerAbstract
  10. {
  11. public function transform(Status $status)
  12. {
  13. return [
  14. 'id' => (string) $status->id,
  15. 'created_at' => $status->created_at->toJSON(),
  16. 'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
  17. 'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
  18. 'sensitive' => (bool) $status->is_nsfw,
  19. 'spoiler_text' => $status->cw_summary ?? '',
  20. 'visibility' => $status->visibility ?? $status->scope,
  21. 'language' => 'en',
  22. 'uri' => $status->permalink(''),
  23. 'url' => $status->url(),
  24. 'replies_count' => $status->reply_count ?? 0,
  25. 'reblogs_count' => $status->reblogs_count ?? 0,
  26. 'favourites_count' => $status->likes_count ?? 0,
  27. 'reblogged' => $status->shared(),
  28. 'favourited' => $status->liked(),
  29. 'muted' => false,
  30. 'bookmarked' => false,
  31. 'pinned' => false,
  32. 'content' => $status->rendered ?? $status->caption ?? '',
  33. 'reblog' => null,
  34. 'application' => [
  35. 'name' => 'web',
  36. 'website' => null
  37. ],
  38. 'mentions' => [],
  39. 'tags' => [],
  40. 'emojis' => [],
  41. 'card' => null,
  42. 'poll' => null,
  43. 'media_attachments' => MediaService::get($status->id),
  44. 'account' => ProfileService::get($status->profile_id),
  45. 'tags' => StatusHashtagService::statusTags($status->id),
  46. ];
  47. }
  48. }