GroupPostTransformer.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Transformer\Api;
  3. use App\Status;
  4. use League\Fractal;
  5. use Cache;
  6. use App\Services\AccountService;
  7. use App\Services\HashidService;
  8. use App\Services\LikeService;
  9. use App\Services\Groups\GroupMediaService;
  10. use App\Services\MediaTagService;
  11. use App\Services\StatusService;
  12. use App\Services\StatusHashtagService;
  13. use App\Services\StatusLabelService;
  14. use App\Services\StatusMentionService;
  15. use App\Services\PollService;
  16. use App\Models\CustomEmoji;
  17. use App\Util\Lexer\Autolink;
  18. use Purify;
  19. class GroupPostTransformer extends Fractal\TransformerAbstract
  20. {
  21. public function transform($status)
  22. {
  23. return [
  24. 'id' => (string) $status->id,
  25. 'gid' => $status->group_id ? (string) $status->group_id : null,
  26. 'url' => '/groups/' . $status->group_id . '/p/' . $status->id,
  27. 'content' => $status->caption,
  28. 'content_text' => $status->caption,
  29. 'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
  30. 'reblogs_count' => $status->reblogs_count ?? 0,
  31. 'favourites_count' => $status->likes_count ?? 0,
  32. 'reblogged' => null,
  33. 'favourited' => null,
  34. 'muted' => null,
  35. 'sensitive' => (bool) $status->is_nsfw,
  36. 'spoiler_text' => $status->cw_summary ?? '',
  37. 'visibility' => $status->visibility,
  38. 'application' => [
  39. 'name' => 'web',
  40. 'website' => null
  41. ],
  42. 'language' => null,
  43. 'pf_type' => $status->type,
  44. 'reply_count' => (int) $status->reply_count ?? 0,
  45. 'comments_disabled' => (bool) $status->comments_disabled,
  46. 'thread' => false,
  47. 'media_attachments' => GroupMediaService::get($status->id),
  48. 'replies' => [],
  49. 'parent' => [],
  50. 'place' => null,
  51. 'local' => (bool) !$status->remote_url,
  52. 'account' => AccountService::get($status->profile_id, true),
  53. 'poll' => [],
  54. ];
  55. }
  56. }