mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 16:17:25 +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
77c25ab725
commit
a0c95e6705
@ -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