Filter out notifications with non-existent subjects

ref  . 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.
This commit is contained in:
Toby Zerner 2017-12-13 15:54:16 +10:30
parent 3e29761d12
commit f4f4ce17b6

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