StatusTransformer.php 3.0 KB

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