StatusStatelessTransformer.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Transformer\Api;
  3. use App\Status;
  4. use League\Fractal;
  5. use Cache;
  6. use App\Services\HashidService;
  7. use App\Services\LikeService;
  8. use App\Services\MediaService;
  9. use App\Services\MediaTagService;
  10. use App\Services\StatusHashtagService;
  11. use App\Services\StatusLabelService;
  12. use App\Services\StatusMentionService;
  13. use App\Services\ProfileService;
  14. use App\Services\PollService;
  15. class StatusStatelessTransformer extends Fractal\TransformerAbstract
  16. {
  17. public function transform(Status $status)
  18. {
  19. $taggedPeople = MediaTagService::get($status->id);
  20. $poll = $status->type === 'poll' ? PollService::get($status->id) : null;
  21. return [
  22. '_v' => 1,
  23. 'id' => (string) $status->id,
  24. 'shortcode' => HashidService::encode($status->id),
  25. 'uri' => $status->url(),
  26. 'url' => $status->url(),
  27. 'in_reply_to_id' => (string) $status->in_reply_to_id,
  28. 'in_reply_to_account_id' => (string) $status->in_reply_to_profile_id,
  29. 'reblog' => null,
  30. 'content' => $status->rendered ?? $status->caption,
  31. 'content_text' => $status->caption,
  32. 'created_at' => $status->created_at->format('c'),
  33. 'emojis' => [],
  34. 'reblogs_count' => 0,
  35. 'favourites_count' => $status->likes_count ?? 0,
  36. 'reblogged' => null,
  37. 'favourited' => null,
  38. 'muted' => null,
  39. 'sensitive' => (bool) $status->is_nsfw,
  40. 'spoiler_text' => $status->cw_summary ?? '',
  41. 'visibility' => $status->scope ?? $status->visibility,
  42. 'application' => [
  43. 'name' => 'web',
  44. 'website' => null
  45. ],
  46. 'language' => null,
  47. 'pinned' => null,
  48. 'mentions' => StatusMentionService::get($status->id),
  49. 'tags' => [],
  50. 'pf_type' => $status->type ?? $status->setType(),
  51. 'reply_count' => (int) $status->reply_count,
  52. 'comments_disabled' => $status->comments_disabled ? true : false,
  53. 'thread' => false,
  54. 'replies' => [],
  55. 'parent' => [],
  56. 'place' => $status->place,
  57. 'local' => (bool) $status->local,
  58. 'taggedPeople' => $taggedPeople,
  59. 'label' => StatusLabelService::get($status),
  60. 'liked_by' => LikeService::likedBy($status),
  61. 'media_attachments' => MediaService::get($status->id),
  62. 'account' => ProfileService::get($status->profile_id),
  63. 'tags' => StatusHashtagService::statusTags($status->id),
  64. 'poll' => $poll
  65. ];
  66. }
  67. }