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