From d0b356be2c7126c4d37a8d369a52aa036fdcc119 Mon Sep 17 00:00:00 2001 From: Josef Citrine Date: Sun, 28 Aug 2016 01:01:37 +0100 Subject: [PATCH] Notification API correctly handles invalid resources --- app/Http/Controllers/Api/Web/NotificationsController.php | 4 +++- app/Models/Activity.php | 4 +--- app/Models/Notification.php | 4 ++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/Api/Web/NotificationsController.php b/app/Http/Controllers/Api/Web/NotificationsController.php index 10a25a37..3a08f1af 100644 --- a/app/Http/Controllers/Api/Web/NotificationsController.php +++ b/app/Http/Controllers/Api/Web/NotificationsController.php @@ -42,7 +42,9 @@ class NotificationsController extends ApiControllerBase ->take(20) ->get(); - return ['notifications' => $notifications->toArray()]; + $outputArray = $notifications->toArray(); + + return ['notifications' => array_values(array_filter($outputArray))]; } /** diff --git a/app/Models/Activity.php b/app/Models/Activity.php index 83ff01ef..03349f43 100644 --- a/app/Models/Activity.php +++ b/app/Models/Activity.php @@ -151,9 +151,6 @@ class Activity extends Model { public function getThumbnailUrlAttribute() { - if (is_null($this->resource)) - return "/images/icons/profile_small.png"; - switch ($this->resource_type) { case User::class: return $this->resource->getAvatarUrl(Image::THUMBNAIL); @@ -172,6 +169,7 @@ class Activity extends Model { } public function getTitleFromActivityType() { + switch($this->activity_type) { case static::TYPE_PUBLISHED_TRACK: return "Pony.fm - New track"; diff --git a/app/Models/Notification.php b/app/Models/Notification.php index 9379a827..23432ac7 100644 --- a/app/Models/Notification.php +++ b/app/Models/Notification.php @@ -76,6 +76,10 @@ class Notification extends Model { } public function toArray() { + if (is_null($this->activity->resource)) { + return ''; + } + return [ 'id' => $this->id, 'date' => $this->activity->created_at->toAtomString(),