mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Update NotificationTransformer
This commit is contained in:
parent
1c900a4ba4
commit
95bcb50329
1 changed files with 18 additions and 4 deletions
|
@ -2,7 +2,10 @@
|
|||
|
||||
namespace App\Transformer\Api;
|
||||
|
||||
use App\Notification;
|
||||
use App\{
|
||||
Notification,
|
||||
Status
|
||||
};
|
||||
use League\Fractal;
|
||||
|
||||
class NotificationTransformer extends Fractal\TransformerAbstract
|
||||
|
@ -10,6 +13,7 @@ class NotificationTransformer extends Fractal\TransformerAbstract
|
|||
protected $defaultIncludes = [
|
||||
'account',
|
||||
'status',
|
||||
'relationship'
|
||||
];
|
||||
|
||||
public function transform(Notification $notification)
|
||||
|
@ -30,9 +34,14 @@ class NotificationTransformer extends Fractal\TransformerAbstract
|
|||
|
||||
public function includeStatus(Notification $notification)
|
||||
{
|
||||
$item = $notification->item;
|
||||
if(is_object($item) && get_class($item) === 'App\Status') {
|
||||
return $this->item($item, new StatusTransformer());
|
||||
$item = $notification;
|
||||
if($item->item_id && $item->item_type == 'App\Status') {
|
||||
$status = Status::with('media')->find($item->item_id);
|
||||
if($status) {
|
||||
return $this->item($status, new StatusTransformer());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -50,4 +59,9 @@ class NotificationTransformer extends Fractal\TransformerAbstract
|
|||
];
|
||||
return $verbs[$verb];
|
||||
}
|
||||
|
||||
public function includeRelationship(Notification $notification)
|
||||
{
|
||||
return $this->item($notification->actor, new RelationshipTransformer());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue