1
0

StatusStatelessTransformer.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Transformer\Api;
  3. use App\Models\CustomEmoji;
  4. use App\Services\AccountService;
  5. use App\Services\HashidService;
  6. use App\Services\LikeService;
  7. use App\Services\MediaService;
  8. use App\Services\MediaTagService;
  9. use App\Services\PollService;
  10. use App\Services\StatusHashtagService;
  11. use App\Services\StatusLabelService;
  12. use App\Services\StatusMentionService;
  13. use App\Services\StatusService;
  14. use App\Status;
  15. use App\Util\Lexer\Autolink;
  16. use League\Fractal;
  17. class StatusStatelessTransformer extends Fractal\TransformerAbstract
  18. {
  19. public function transform(Status $status)
  20. {
  21. $taggedPeople = MediaTagService::get($status->id);
  22. $poll = $status->type === 'poll' ? PollService::get($status->id) : null;
  23. $rendered = $status->caption ? nl2br(Autolink::create()->autolink($status->caption)) : "";
  24. return [
  25. '_v' => 1,
  26. 'id' => (string) $status->id,
  27. //'gid' => $status->group_id ? (string) $status->group_id : null,
  28. 'shortcode' => HashidService::encode($status->id),
  29. 'uri' => $status->url(),
  30. 'url' => $status->url(),
  31. 'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
  32. 'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
  33. 'reblog' => $status->reblog_of_id ? StatusService::get($status->reblog_of_id, false) : null,
  34. 'content' => $rendered,
  35. 'content_text' => $status->caption,
  36. 'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
  37. 'emojis' => CustomEmoji::scan($status->caption),
  38. 'reblogs_count' => $status->reblogs_count ?? 0,
  39. 'favourites_count' => $status->likes_count ?? 0,
  40. 'reblogged' => null,
  41. 'favourited' => null,
  42. 'muted' => null,
  43. 'sensitive' => (bool) $status->is_nsfw,
  44. 'spoiler_text' => $status->cw_summary ?? '',
  45. 'visibility' => $status->scope ?? $status->visibility,
  46. 'application' => [
  47. 'name' => 'web',
  48. 'website' => null,
  49. ],
  50. 'language' => null,
  51. 'mentions' => StatusMentionService::get($status->id),
  52. 'pf_type' => $status->type ?? $status->setType(),
  53. 'reply_count' => (int) $status->reply_count,
  54. 'comments_disabled' => (bool) $status->comments_disabled,
  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' => AccountService::get($status->profile_id, true),
  65. 'tags' => StatusHashtagService::statusTags($status->id),
  66. 'poll' => $poll,
  67. 'edited_at' => $status->edited_at ? str_replace('+00:00', 'Z', $status->edited_at->format(DATE_RFC3339_EXTENDED)) : null,
  68. 'pinned' => (bool) $status->pinned_order,
  69. ];
  70. }
  71. }