2019-09-26 07:30:15 +00:00
|
|
|
<?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),
|
2019-09-27 04:24:03 +00:00
|
|
|
'created_at' => (string) $notification->created_at->toJSON(),
|
2019-09-26 07:30:15 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2020-08-25 00:53:37 +00:00
|
|
|
return;
|
2019-09-26 07:30:15 +00:00
|
|
|
}
|
|
|
|
} else {
|
2020-08-25 00:53:37 +00:00
|
|
|
return;
|
2019-09-26 07:30:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function replaceTypeVerb($verb)
|
|
|
|
{
|
|
|
|
$verbs = [
|
2020-12-13 23:03:44 +00:00
|
|
|
'dm' => 'direct',
|
2019-09-26 07:30:15 +00:00
|
|
|
'follow' => 'follow',
|
|
|
|
'mention' => 'mention',
|
2019-09-27 03:58:40 +00:00
|
|
|
'share' => 'reblog',
|
2019-09-26 07:30:15 +00:00
|
|
|
'like' => 'favourite',
|
2019-09-27 03:58:40 +00:00
|
|
|
'comment' => 'mention',
|
2020-12-13 23:03:44 +00:00
|
|
|
'admin.user.modlog.comment' => 'modlog',
|
|
|
|
'tagged' => 'tagged'
|
2019-09-26 07:30:15 +00:00
|
|
|
];
|
|
|
|
return $verbs[$verb];
|
|
|
|
}
|
|
|
|
}
|