From a0c95e6705fdebc6a87c030bcb830511e02dc9ae Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Wed, 13 Dec 2017 15:54:16 +1030 Subject: [PATCH] Filter out notifications with non-existent subjects ref #1025 #1238. This should prevent the frontend from crashing when opening the notifications menu, but we still need to make sure notifications are deleted properly when subjects are deleted. --- src/Api/Controller/ListNotificationsController.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Api/Controller/ListNotificationsController.php b/src/Api/Controller/ListNotificationsController.php index 284f103b3..f53f3be60 100644 --- a/src/Api/Controller/ListNotificationsController.php +++ b/src/Api/Controller/ListNotificationsController.php @@ -76,6 +76,10 @@ class ListNotificationsController extends AbstractCollectionController $offset = $this->extractOffset($request); $include = $this->extractInclude($request); + if (! in_array('subject', $include)) { + $include[] = 'subject'; + } + $notifications = $this->notifications->findByUser($actor, $limit + 1, $offset) ->load(array_diff($include, ['subject.discussion'])) ->all(); @@ -95,6 +99,10 @@ class ListNotificationsController extends AbstractCollectionController $areMoreResults ? null : 0 ); + $notifications = array_filter($notifications, function ($notification) { + return ! $notification->subjectModel || $notification->subject; + }); + if (in_array('subject.discussion', $include)) { $this->loadSubjectDiscussions($notifications); }