Update mastoapi transformers

This commit is contained in:
Daniel Supernault 2022-01-02 23:26:18 -07:00
parent 41cc741be6
commit 89206d6e1f
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
4 changed files with 15 additions and 16 deletions

View File

@ -11,7 +11,6 @@ class AccountTransformer extends Fractal\TransformerAbstract
public function transform(Profile $profile)
{
$local = $profile->domain == null;
$is_admin = !$local ? false : $profile->user->is_admin;
$username = $local ? $profile->username : explode('@', substr($profile->username, 1))[0];
return [
'id' => (string) $profile->id,
@ -19,22 +18,21 @@ class AccountTransformer extends Fractal\TransformerAbstract
'acct' => $username,
'display_name' => $profile->name,
'locked' => (bool) $profile->is_private,
'bot' => false,
'created_at' => $profile->created_at->toJSON(),
'followers_count' => $profile->followerCount(),
'following_count' => $profile->followingCount(),
'statuses_count' => (int) $profile->statusCount(),
'note' => $profile->bio ?? '',
'url' => $profile->url(),
'avatar' => $profile->avatarUrl(),
'avatar_static' => $profile->avatarUrl(),
'header' => '',
'header_static' => '',
'followers_count' => (int) $profile->followerCount(),
'following_count' => (int) $profile->followingCount(),
'statuses_count' => (int) $profile->statusCount(),
'last_status_at' => optional($profile->last_status_at)->toJSON(),
'emojis' => [],
'moved' => null,
'fields' => null,
'bot' => false,
'software' => 'pixelfed',
'is_admin' => (bool) $is_admin,
'fields' => [],
];
}
}

View File

@ -13,10 +13,9 @@ class MediaTransformer extends Fractal\TransformerAbstract
'id' => (string) $media->id,
'type' => lcfirst($media->activityVerb()),
'url' => $media->url(),
'remote_url' => null,
'preview_url' => $media->thumbnailUrl(),
'text_url' => null,
'meta' => null,
'remote_url' => $media->remote_url,
'text_url' => $media->url(),
'description' => $media->caption,
'blurhash' => $media->blurhash ?? 'U4Rfzst8?bt7ogayj[j[~pfQ9Goe%Mj[WBay'
];
@ -38,4 +37,4 @@ class MediaTransformer extends Fractal\TransformerAbstract
return $res;
}
}
}

View File

@ -9,11 +9,13 @@ class MentionTransformer extends Fractal\TransformerAbstract
{
public function transform(Profile $profile)
{
$local = $profile->domain == null;
$username = $local ? $profile->username : explode('@', substr($profile->username, 1))[0];
return [
'id' => (string) $profile->id,
'url' => $profile->url(),
'username' => $profile->username,
'acct' => $profile->username,
'acct' => $username,
];
}
}

View File

@ -17,14 +17,14 @@ class StatusTransformer extends Fractal\TransformerAbstract
'id' => (string) $status->id,
'created_at' => $status->created_at->toJSON(),
'in_reply_to_id' => $status->in_reply_to_id ? (string) $status->in_reply_to_id : null,
'in_reply_to_account_id' => $status->in_reply_to_profile_id,
'in_reply_to_account_id' => $status->in_reply_to_profile_id ? (string) $status->in_reply_to_profile_id : null,
'sensitive' => (bool) $status->is_nsfw,
'spoiler_text' => $status->cw_summary ?? '',
'visibility' => $status->visibility ?? $status->scope,
'language' => 'en',
'uri' => $status->url(),
'uri' => $status->permalink(''),
'url' => $status->url(),
'replies_count' => 0,
'replies_count' => $status->reply_count ?? 0,
'reblogs_count' => $status->reblogs_count ?? 0,
'favourites_count' => $status->likes_count ?? 0,
'reblogged' => $status->shared(),