2018-11-28 23:51:47 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Transformer\Api;
|
|
|
|
|
2021-10-07 03:27:13 -06:00
|
|
|
use App\Notification;
|
|
|
|
use App\Services\AccountService;
|
2020-12-13 17:28:33 -07:00
|
|
|
use App\Services\HashidService;
|
2021-10-19 19:49:44 -06:00
|
|
|
use App\Services\RelationshipService;
|
2021-10-07 03:27:13 -06:00
|
|
|
use App\Services\StatusService;
|
2018-11-28 23:51:47 -07:00
|
|
|
use League\Fractal;
|
|
|
|
|
|
|
|
class NotificationTransformer extends Fractal\TransformerAbstract
|
|
|
|
{
|
|
|
|
public function transform(Notification $notification)
|
|
|
|
{
|
2021-10-07 03:27:13 -06:00
|
|
|
$res = [
|
2019-01-27 19:40:36 -07:00
|
|
|
'id' => (string) $notification->id,
|
2018-11-28 23:51:47 -07:00
|
|
|
'type' => $this->replaceTypeVerb($notification->action),
|
2019-09-20 23:45:19 -06:00
|
|
|
'created_at' => (string) $notification->created_at->format('c'),
|
2018-11-28 23:51:47 -07:00
|
|
|
];
|
|
|
|
|
2021-10-07 03:27:13 -06:00
|
|
|
$n = $notification;
|
|
|
|
|
|
|
|
if($n->actor_id) {
|
|
|
|
$res['account'] = AccountService::get($n->actor_id);
|
2021-10-19 19:49:44 -06:00
|
|
|
$res['relationship'] = RelationshipService::get($n->actor_id, $n->profile_id);
|
2021-10-07 03:27:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
if($n->item_id && $n->item_type == 'App\Status') {
|
|
|
|
$res['status'] = StatusService::get($n->item_id, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if($n->item_id && $n->item_type == 'App\ModLog') {
|
|
|
|
$ml = $n->item;
|
|
|
|
$res['modlog'] = [
|
|
|
|
'id' => $ml->object_uid,
|
|
|
|
'url' => url('/i/admin/users/modlogs/' . $ml->object_uid)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
if($n->item_id && $n->item_type == 'App\MediaTag') {
|
|
|
|
$ml = $n->item;
|
|
|
|
$res['tagged'] = [
|
|
|
|
'username' => $ml->tagged_username,
|
|
|
|
'post_url' => '/p/'.HashidService::encode($ml->status_id)
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $res;
|
2018-11-28 23:51:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public function replaceTypeVerb($verb)
|
|
|
|
{
|
|
|
|
$verbs = [
|
2020-11-18 14:19:02 -07:00
|
|
|
'dm' => 'direct',
|
2018-11-28 23:51:47 -07:00
|
|
|
'follow' => 'follow',
|
|
|
|
'mention' => 'mention',
|
|
|
|
'reblog' => 'share',
|
2019-01-14 22:34:27 -07:00
|
|
|
'share' => 'share',
|
2018-11-28 23:51:47 -07:00
|
|
|
'like' => 'favourite',
|
2021-10-07 03:27:13 -06:00
|
|
|
'group:like' => 'favourite',
|
2018-12-10 12:00:50 -07:00
|
|
|
'comment' => 'comment',
|
2020-07-15 10:37:37 -06:00
|
|
|
'admin.user.modlog.comment' => 'modlog',
|
2021-09-03 21:23:43 -06:00
|
|
|
'tagged' => 'tagged',
|
|
|
|
'group:comment' => 'group:comment',
|
|
|
|
'story:react' => 'story:react',
|
2021-10-07 03:27:13 -06:00
|
|
|
'story:comment' => 'story:comment',
|
|
|
|
'group:join:approved' => 'group:join:approved',
|
|
|
|
'group:join:rejected' => 'group:join:rejected'
|
2018-11-28 23:51:47 -07:00
|
|
|
];
|
2021-10-07 03:27:13 -06:00
|
|
|
|
|
|
|
if(!isset($verbs[$verb])) {
|
|
|
|
return $verb;
|
|
|
|
}
|
|
|
|
|
2018-11-28 23:51:47 -07:00
|
|
|
return $verbs[$verb];
|
|
|
|
}
|
|
|
|
}
|