mirror of
https://github.com/pixelfed/pixelfed.git
synced 2025-02-04 10:50:46 +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;
|
namespace App\Transformer\Api;
|
||||||
|
|
||||||
use App\Notification;
|
use App\{
|
||||||
|
Notification,
|
||||||
|
Status
|
||||||
|
};
|
||||||
use League\Fractal;
|
use League\Fractal;
|
||||||
|
|
||||||
class NotificationTransformer extends Fractal\TransformerAbstract
|
class NotificationTransformer extends Fractal\TransformerAbstract
|
||||||
|
@ -10,6 +13,7 @@ class NotificationTransformer extends Fractal\TransformerAbstract
|
||||||
protected $defaultIncludes = [
|
protected $defaultIncludes = [
|
||||||
'account',
|
'account',
|
||||||
'status',
|
'status',
|
||||||
|
'relationship'
|
||||||
];
|
];
|
||||||
|
|
||||||
public function transform(Notification $notification)
|
public function transform(Notification $notification)
|
||||||
|
@ -30,9 +34,14 @@ class NotificationTransformer extends Fractal\TransformerAbstract
|
||||||
|
|
||||||
public function includeStatus(Notification $notification)
|
public function includeStatus(Notification $notification)
|
||||||
{
|
{
|
||||||
$item = $notification->item;
|
$item = $notification;
|
||||||
if(is_object($item) && get_class($item) === 'App\Status') {
|
if($item->item_id && $item->item_type == 'App\Status') {
|
||||||
return $this->item($item, new StatusTransformer());
|
$status = Status::with('media')->find($item->item_id);
|
||||||
|
if($status) {
|
||||||
|
return $this->item($status, new StatusTransformer());
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -50,4 +59,9 @@ class NotificationTransformer extends Fractal\TransformerAbstract
|
||||||
];
|
];
|
||||||
return $verbs[$verb];
|
return $verbs[$verb];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function includeRelationship(Notification $notification)
|
||||||
|
{
|
||||||
|
return $this->item($notification->actor, new RelationshipTransformer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue