mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-12-27 15:33:17 +00:00
59 lines
1.2 KiB
PHP
59 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Transformer\Api\Mastodon\v1;
|
|
|
|
use App\{
|
|
Notification,
|
|
Status
|
|
};
|
|
use League\Fractal;
|
|
|
|
class NotificationTransformer extends Fractal\TransformerAbstract
|
|
{
|
|
protected $defaultIncludes = [
|
|
'account',
|
|
'status',
|
|
];
|
|
|
|
public function transform(Notification $notification)
|
|
{
|
|
return [
|
|
'id' => (string) $notification->id,
|
|
'type' => $this->replaceTypeVerb($notification->action),
|
|
'created_at' => (string) $notification->created_at->toJSON(),
|
|
];
|
|
}
|
|
|
|
public function includeAccount(Notification $notification)
|
|
{
|
|
return $this->item($notification->actor, new AccountTransformer());
|
|
}
|
|
|
|
public function includeStatus(Notification $notification)
|
|
{
|
|
$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;
|
|
}
|
|
}
|
|
|
|
public function replaceTypeVerb($verb)
|
|
{
|
|
$verbs = [
|
|
'follow' => 'follow',
|
|
'mention' => 'mention',
|
|
'share' => 'reblog',
|
|
'like' => 'favourite',
|
|
'comment' => 'mention',
|
|
'admin.user.modlog.comment' => 'modlog'
|
|
];
|
|
return $verbs[$verb];
|
|
}
|
|
}
|