StatusStateless.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Resources\Json\JsonResource;
  4. use Cache;
  5. use App\Services\AccountService;
  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\PollService;
  14. use App\Models\CustomEmoji;
  15. class StatusStateless extends JsonResource
  16. {
  17. /**
  18. * Transform the resource into an array.
  19. *
  20. * @param \Illuminate\Http\Request $request
  21. * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
  22. */
  23. public function toArray($request)
  24. {
  25. $status = $this;
  26. $taggedPeople = MediaTagService::get($status->id);
  27. $poll = $status->type === 'poll' ? PollService::get($status->id) : null;
  28. return [
  29. '_v' => 1,
  30. 'id' => (string) $status->id,
  31. //'gid' => $status->group_id ? (string) $status->group_id : null,
  32. 'shortcode' => HashidService::encode($status->id),
  33. 'uri' => $status->url(),
  34. 'url' => $status->url(),
  35. 'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
  36. 'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
  37. 'reblog' => null,
  38. 'content' => $status->rendered ?? $status->caption,
  39. 'content_text' => $status->caption,
  40. 'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
  41. 'emojis' => CustomEmoji::scan($status->caption),
  42. 'reblogs_count' => $status->reblogs_count ?? 0,
  43. 'favourites_count' => $status->likes_count ?? 0,
  44. 'reblogged' => null,
  45. 'favourited' => null,
  46. 'muted' => null,
  47. 'sensitive' => (bool) $status->is_nsfw,
  48. 'spoiler_text' => $status->cw_summary ?? '',
  49. 'visibility' => $status->scope ?? $status->visibility,
  50. 'application' => [
  51. 'name' => 'web',
  52. 'website' => null
  53. ],
  54. 'language' => null,
  55. 'mentions' => StatusMentionService::get($status->id),
  56. 'pf_type' => $status->type ?? $status->setType(),
  57. 'reply_count' => (int) $status->reply_count,
  58. 'comments_disabled' => (bool) $status->comments_disabled,
  59. 'thread' => false,
  60. 'replies' => [],
  61. 'parent' => [],
  62. 'place' => $status->place,
  63. 'local' => (bool) $status->local,
  64. 'taggedPeople' => $taggedPeople,
  65. 'liked_by' => LikeService::likedBy($status),
  66. 'media_attachments' => MediaService::get($status->id),
  67. 'account' => AccountService::get($status->profile_id, true),
  68. 'tags' => StatusHashtagService::statusTags($status->id),
  69. 'poll' => $poll
  70. ];
  71. }
  72. }