1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-23 00:05:29 +00:00
pixelfed/app/Http/Resources/StatusStateless.php

77 lines
3 KiB
PHP
Raw Normal View History

2023-01-28 02:29:44 +00:00
<?php
namespace App\Http\Resources;
2024-11-19 09:53:39 +00:00
use App\Models\CustomEmoji;
2023-01-28 02:29:44 +00:00
use App\Services\AccountService;
use App\Services\HashidService;
use App\Services\LikeService;
use App\Services\MediaService;
use App\Services\MediaTagService;
2024-11-19 09:53:39 +00:00
use App\Services\PollService;
2023-01-28 02:29:44 +00:00
use App\Services\StatusHashtagService;
use App\Services\StatusMentionService;
2024-11-19 09:53:39 +00:00
use App\Util\Lexer\Autolink;
use Illuminate\Http\Resources\Json\JsonResource;
2023-01-28 02:29:44 +00:00
class StatusStateless extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
$status = $this;
$taggedPeople = MediaTagService::get($status->id);
$poll = $status->type === 'poll' ? PollService::get($status->id) : null;
2024-11-19 09:53:39 +00:00
$autoLink = $status->caption ? Autolink::create()->autolink($status->caption) : null;
2023-01-28 02:29:44 +00:00
return [
2024-11-19 09:53:39 +00:00
'_v' => 1,
'id' => (string) $status->id,
2023-01-28 02:29:44 +00:00
//'gid' => $status->group_id ? (string) $status->group_id : null,
2024-11-19 09:53:39 +00:00
'shortcode' => HashidService::encode($status->id),
'uri' => $status->url(),
'url' => $status->url(),
'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 ? (string) $status->in_reply_to_profile_id : null,
'reblog' => null,
'content' => $autoLink,
'content_text' => $status->caption,
'created_at' => str_replace('+00:00', 'Z', $status->created_at->format(DATE_RFC3339_EXTENDED)),
'emojis' => CustomEmoji::scan($status->caption),
'reblogs_count' => $status->reblogs_count ?? 0,
'favourites_count' => $status->likes_count ?? 0,
'reblogged' => null,
'favourited' => null,
'muted' => null,
'sensitive' => (bool) $status->is_nsfw,
'spoiler_text' => $status->cw_summary ?? '',
'visibility' => $status->scope ?? $status->visibility,
'application' => [
'name' => 'web',
'website' => null,
],
'language' => null,
'mentions' => StatusMentionService::get($status->id),
'pf_type' => $status->type ?? $status->setType(),
'reply_count' => (int) $status->reply_count,
'comments_disabled' => (bool) $status->comments_disabled,
'thread' => false,
'replies' => [],
'parent' => [],
'place' => $status->place,
'local' => (bool) $status->local,
'taggedPeople' => $taggedPeople,
'liked_by' => LikeService::likedBy($status),
'media_attachments' => MediaService::get($status->id),
'account' => AccountService::get($status->profile_id, true),
'tags' => StatusHashtagService::statusTags($status->id),
'poll' => $poll,
2023-01-28 02:29:44 +00:00
];
}
}