1
0
Fork 0

Merge pull request #2487 from pixelfed/staging

Staging
This commit is contained in:
daniel 2020-12-12 23:53:37 -07:00 committed by GitHub
commit d398358788
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 23 deletions

View File

@ -635,7 +635,7 @@ class PublicApiController extends Controller
->orderByDesc('id') ->orderByDesc('id')
->get(); ->get();
$resource = new Fractal\Resource\Collection($timeline, new StatusTransformer()); $resource = new Fractal\Resource\Collection($timeline, new StatusStatelessTransformer());
$res = $this->fractal->createData($resource)->toArray(); $res = $this->fractal->createData($resource)->toArray();
return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES); return response()->json($res, 200, [], JSON_PRETTY_PRINT|JSON_UNESCAPED_SLASHES);

View File

@ -12,9 +12,7 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract
{ {
protected $defaultIncludes = [ protected $defaultIncludes = [
'account', 'account',
'mentions',
'media_attachments', 'media_attachments',
'tags',
]; ];
public function transform(Status $status) public function transform(Status $status)
@ -30,23 +28,23 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract
'in_reply_to_account_id' => $status->in_reply_to_profile_id, 'in_reply_to_account_id' => $status->in_reply_to_profile_id,
'reblog' => null, 'reblog' => null,
'content' => $status->rendered ?? $status->caption, 'content' => $status->rendered ?? $status->caption,
'content_text' => $status->caption,
'created_at' => $status->created_at->format('c'), 'created_at' => $status->created_at->format('c'),
'emojis' => [], 'emojis' => [],
'reblogs_count' => $status->shares()->count(), 'reblogs_count' => $status->reblogs_count ?? 0,
'favourites_count' => $status->likes()->count(), 'favourites_count' => $status->likes_count ?? 0,
'reblogged' => null, 'reblogged' => null,
'favourited' => null, 'favourited' => null,
'muted' => null, 'muted' => null,
'sensitive' => (bool) $status->is_nsfw, 'sensitive' => (bool) $status->is_nsfw,
'spoiler_text' => $status->cw_summary, 'spoiler_text' => $status->cw_summary ?? '',
'visibility' => $status->visibility, 'visibility' => $status->visibility ?? $status->scope,
'application' => [ 'application' => [
'name' => 'web', 'name' => 'web',
'website' => null 'website' => null
], ],
'language' => null, 'language' => null,
'pinned' => null, 'pinned' => null,
'mentions' => [], 'mentions' => [],
'tags' => [], 'tags' => [],
'pf_type' => $status->type ?? $status->setType(), 'pf_type' => $status->type ?? $status->setType(),
@ -68,27 +66,13 @@ class StatusStatelessTransformer extends Fractal\TransformerAbstract
return $this->item($account, new AccountTransformer()); return $this->item($account, new AccountTransformer());
} }
public function includeMentions(Status $status)
{
$mentions = $status->mentions;
return $this->collection($mentions, new MentionTransformer());
}
public function includeMediaAttachments(Status $status) public function includeMediaAttachments(Status $status)
{ {
return Cache::remember('status:transformer:media:attachments:'.$status->id, now()->addMinutes(3), function() use($status) { return Cache::remember('status:transformer:media:attachments:'.$status->id, now()->addMinutes(3), function() use($status) {
if(in_array($status->type, ['photo', 'video', 'photo:album', 'loop'])) { if(in_array($status->type, ['photo', 'video', 'video:album', 'photo:album', 'loop', 'photo:video:album'])) {
$media = $status->media()->orderBy('order')->get(); $media = $status->media()->orderBy('order')->get();
return $this->collection($media, new MediaTransformer()); return $this->collection($media, new MediaTransformer());
} }
}); });
} }
public function includeTags(Status $status)
{
$tags = $status->hashtags;
return $this->collection($tags, new HashtagTransformer());
}
} }