From fec974108644057b95d2398f778005991fdb9639 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 28 Nov 2018 23:51:47 -0700 Subject: [PATCH] Add API NotificationTransformer --- .../Api/NotificationTransformer.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 app/Transformer/Api/NotificationTransformer.php diff --git a/app/Transformer/Api/NotificationTransformer.php b/app/Transformer/Api/NotificationTransformer.php new file mode 100644 index 00000000..d5afa1b6 --- /dev/null +++ b/app/Transformer/Api/NotificationTransformer.php @@ -0,0 +1,51 @@ + $notification->id, + 'type' => $this->replaceTypeVerb($notification->action), + 'created_at' => (string) $notification->created_at, + 'account' => null, + 'status' => null + ]; + } + + public function includeAccount(Notification $notification) + { + return $this->item($notification->actor, new AccountTransformer()); + } + + public function includeStatus(Notification $notification) + { + $item = $notification->item; + if(get_class($item) === 'App\Status') { + return $this->item($item, new StatusTransformer()); + } else { + return null; + } + } + + public function replaceTypeVerb($verb) + { + $verbs = [ + 'follow' => 'follow', + 'mention' => 'mention', + 'reblog' => 'share', + 'like' => 'favourite', + ]; + return $verbs[$verb]; + } +}