mirror of
https://github.com/flarum/framework.git
synced 2025-04-02 15:15:24 +08:00
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.
This commit is contained in:
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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user