Skip to content

Commit

Permalink
Add uniform "type" field to activity and microblog resource
Browse files Browse the repository at this point in the history
  • Loading branch information
danon committed Nov 22, 2023
1 parent 2520886 commit f6e88ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions app/Http/Resources/ActivityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function toArray($request)
'headline' => $this->headline(),
'user_id' => $this->user_id,
'object' => strtolower(class_basename($this->content_type)),
'type' => strtolower(class_basename($this->content_type)),
'user' => [
'photo' => $this->user_id ? $this->user->photo : ''
]
Expand Down
19 changes: 10 additions & 9 deletions app/Http/Resources/MicroblogResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function __construct($resource)
{
parent::__construct($resource);

TagResource::urlResolver(fn ($name) => route('microblog.tag', [urlencode($name)]));
TagResource::urlResolver(fn($name) => route('microblog.tag', [urlencode($name)]));
}

public function toArray($request)
Expand All @@ -21,14 +21,15 @@ public function toArray($request)
unset($result['media']);

return array_merge_recursive($result, [
'assets' => $assets,
'tags' => $this->whenLoaded('tags', fn () => TagResource::collection($this->resource->tags)),
'is_sponsored' => $this->resource->is_sponsored,
'metadata' => encrypt([Microblog::class => $this->resource->id]),
'deleted_at' => $this->resource->deleted_at,

'permissions' => [
'moderate' => $this->when($request->user(), fn () => $request->user()->can('moderate', $this->resource), false)
'type' => 'microblog',
'assets' => $assets,
'tags' => $this->whenLoaded('tags', fn() => TagResource::collection($this->resource->tags)),
'is_sponsored' => $this->resource->is_sponsored,
'metadata' => encrypt([Microblog::class => $this->resource->id]),
'deleted_at' => $this->resource->deleted_at,

'permissions' => [
'moderate' => $this->when($request->user(), fn() => $request->user()->can('moderate', $this->resource), false)
]
]);
}
Expand Down

0 comments on commit f6e88ac

Please sign in to comment.