2018-07-12 10:42:17 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Transformer\Api;
|
|
|
|
|
2019-09-01 18:26:54 -06:00
|
|
|
use Auth;
|
2018-07-12 10:42:17 -06:00
|
|
|
use App\Profile;
|
|
|
|
use League\Fractal;
|
2021-05-11 23:25:10 -06:00
|
|
|
use App\Services\PronounService;
|
2018-07-12 10:42:17 -06:00
|
|
|
|
|
|
|
class AccountTransformer extends Fractal\TransformerAbstract
|
|
|
|
{
|
2019-09-01 18:26:54 -06:00
|
|
|
protected $defaultIncludes = [
|
2019-09-30 00:55:49 -06:00
|
|
|
// 'relationship',
|
2019-09-01 18:26:54 -06:00
|
|
|
];
|
|
|
|
|
2018-12-30 21:26:37 -07:00
|
|
|
public function transform(Profile $profile)
|
|
|
|
{
|
2019-09-20 23:15:35 -06:00
|
|
|
$local = $profile->domain == null;
|
|
|
|
$is_admin = !$local ? false : $profile->user->is_admin;
|
|
|
|
$acct = $local ? $profile->username : substr($profile->username, 1);
|
2019-09-20 23:20:22 -06:00
|
|
|
$username = $local ? $profile->username : explode('@', $acct)[0];
|
2018-12-30 21:26:37 -07:00
|
|
|
return [
|
2019-01-27 19:40:36 -07:00
|
|
|
'id' => (string) $profile->id,
|
2019-09-20 23:15:35 -06:00
|
|
|
'username' => $username,
|
|
|
|
'acct' => $acct,
|
2018-12-30 21:26:37 -07:00
|
|
|
'display_name' => $profile->name,
|
2022-03-22 21:56:22 -06:00
|
|
|
'discoverable' => true,
|
2018-12-30 21:26:37 -07:00
|
|
|
'locked' => (bool) $profile->is_private,
|
2022-01-03 00:53:15 -07:00
|
|
|
'followers_count' => (int) $profile->followerCount(),
|
|
|
|
'following_count' => (int) $profile->followingCount(),
|
2019-06-05 01:38:19 -06:00
|
|
|
'statuses_count' => (int) $profile->statusCount(),
|
2019-09-21 00:02:09 -06:00
|
|
|
'note' => $profile->bio ?? '',
|
2022-04-18 01:59:27 -06:00
|
|
|
'note_text' => $profile->bio ? strip_tags($profile->bio) : null,
|
2018-12-30 21:26:37 -07:00
|
|
|
'url' => $profile->url(),
|
|
|
|
'avatar' => $profile->avatarUrl(),
|
2019-06-09 14:13:43 -06:00
|
|
|
'website' => $profile->website,
|
2019-10-29 18:13:44 -06:00
|
|
|
'local' => (bool) $local,
|
2019-09-01 18:26:54 -06:00
|
|
|
'is_admin' => (bool) $is_admin,
|
2020-04-11 21:12:12 -06:00
|
|
|
'created_at' => $profile->created_at->toJSON(),
|
2020-04-26 23:29:24 -06:00
|
|
|
'header_bg' => $profile->header_bg,
|
2021-05-11 23:25:10 -06:00
|
|
|
'last_fetched_at' => optional($profile->last_fetched_at)->toJSON(),
|
2021-12-04 17:34:32 -07:00
|
|
|
'pronouns' => PronounService::get($profile->id),
|
|
|
|
'location' => $profile->location
|
2018-12-30 21:26:37 -07:00
|
|
|
];
|
|
|
|
}
|
2019-09-01 18:26:54 -06:00
|
|
|
|
|
|
|
protected function includeRelationship(Profile $profile)
|
|
|
|
{
|
|
|
|
return $this->item($profile, new RelationshipTransformer());
|
|
|
|
}
|
2018-08-28 03:07:36 +00:00
|
|
|
}
|