Notification API correctly handles invalid resources

This commit is contained in:
Josef Citrine 2016-08-28 01:01:37 +01:00
parent 5311577aa2
commit d0b356be2c
3 changed files with 8 additions and 4 deletions

View file

@ -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))];
}
/**

View file

@ -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";

View file

@ -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(),