AccountTransformer.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Transformer\Api\Mastodon\v1;
  3. use App\Profile;
  4. use League\Fractal;
  5. use Illuminate\Support\Str;
  6. class AccountTransformer extends Fractal\TransformerAbstract
  7. {
  8. public function transform(Profile $profile)
  9. {
  10. $local = $profile->domain == null;
  11. $is_admin = !$local ? false : $profile->user->is_admin;
  12. $username = $local ? $profile->username : explode('@', substr($profile->username, 1))[0];
  13. return [
  14. 'id' => (string) $profile->id,
  15. 'username' => $username,
  16. 'acct' => $username,
  17. 'display_name' => $profile->name,
  18. 'locked' => (bool) $profile->is_private,
  19. 'created_at' => $profile->created_at->toJSON(),
  20. 'followers_count' => $profile->followerCount(),
  21. 'following_count' => $profile->followingCount(),
  22. 'statuses_count' => (int) $profile->statusCount(),
  23. 'note' => $profile->bio ?? '',
  24. 'url' => $profile->url(),
  25. 'avatar' => $profile->avatarUrl(),
  26. 'avatar_static' => $profile->avatarUrl(),
  27. 'header' => '',
  28. 'header_static' => '',
  29. 'emojis' => [],
  30. 'moved' => null,
  31. 'fields' => null,
  32. 'bot' => false,
  33. 'software' => 'pixelfed',
  34. 'is_admin' => (bool) $is_admin,
  35. ];
  36. }
  37. }