1
0

StatusStatelessTransformer.php 3.0 KB

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