pixelfed/app/Transformer/Api/Mastodon/v1/AccountTransformer.php

39 lines
1.1 KiB
PHP
Raw Normal View History

2019-09-26 07:30:15 +00:00
<?php
namespace App\Transformer\Api\Mastodon\v1;
use App\Profile;
use League\Fractal;
2019-10-02 02:53:45 +00:00
use Illuminate\Support\Str;
2019-09-26 07:30:15 +00:00
class AccountTransformer extends Fractal\TransformerAbstract
{
public function transform(Profile $profile)
{
$local = $profile->domain == null;
2019-10-02 02:53:45 +00:00
$username = $local ? $profile->username : explode('@', substr($profile->username, 1))[0];
2019-09-26 07:30:15 +00:00
return [
'id' => (string) $profile->id,
'username' => $username,
2019-10-02 02:53:45 +00:00
'acct' => $username,
2019-09-26 07:30:15 +00:00
'display_name' => $profile->name,
'locked' => (bool) $profile->is_private,
2022-01-03 06:26:18 +00:00
'bot' => false,
2019-09-27 04:24:03 +00:00
'created_at' => $profile->created_at->toJSON(),
2019-09-26 07:30:15 +00:00
'note' => $profile->bio ?? '',
'url' => $profile->url(),
'avatar' => $profile->avatarUrl(),
'avatar_static' => $profile->avatarUrl(),
'header' => '',
'header_static' => '',
2022-01-03 06:26:18 +00:00
'followers_count' => (int) $profile->followerCount(),
'following_count' => (int) $profile->followingCount(),
'statuses_count' => (int) $profile->statusCount(),
'last_status_at' => optional($profile->last_status_at)->toJSON(),
2019-09-26 07:30:15 +00:00
'emojis' => [],
'moved' => null,
2022-01-03 06:26:18 +00:00
'fields' => [],
2019-09-26 07:30:15 +00:00
];
}
}