StatusTransformer.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. 'content' => $status->rendered ?? $status->caption ?? '',
  32. 'reblog' => null,
  33. 'application' => [
  34. 'name' => 'web',
  35. 'website' => null
  36. ],
  37. 'mentions' => [],
  38. 'emojis' => [],
  39. 'card' => null,
  40. 'poll' => null,
  41. 'media_attachments' => MediaService::get($status->id),
  42. 'account' => ProfileService::get($status->profile_id, true),
  43. 'tags' => StatusHashtagService::statusTags($status->id),
  44. ];
  45. }
  46. }