From 22d322aa2a4fb818af78475df720ff92d3b3b8ac Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 28 Jul 2015 17:15:09 +0930 Subject: [PATCH] Don't display notifications with deleted subjects --- framework/core/js/forum/src/components/NotificationList.js | 6 ++++-- framework/core/js/forum/src/components/TerminalPost.js | 1 - framework/core/js/lib/Model.js | 4 ++++ framework/core/src/Api/Serializers/Serializer.php | 3 ++- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/framework/core/js/forum/src/components/NotificationList.js b/framework/core/js/forum/src/components/NotificationList.js index 9ec4ad3b5..fae4c430a 100644 --- a/framework/core/js/forum/src/components/NotificationList.js +++ b/framework/core/js/forum/src/components/NotificationList.js @@ -33,12 +33,14 @@ export default class NotificationList extends Component { app.cache.notifications.forEach(notification => { const subject = notification.subject(); + if (typeof subject === 'undefined') return; + // Get the discussion that this notification is related to. If it's not // directly related to a discussion, it may be related to a post or // other entity which is related to a discussion. - let discussion; + let discussion = false; if (subject instanceof Discussion) discussion = subject; - else if (subject.discussion) discussion = subject.discussion(); + else if (subject && subject.discussion) discussion = subject.discussion(); // If the notification is not related to a discussion directly or // indirectly, then we will assign it to a neutral group. diff --git a/framework/core/js/forum/src/components/TerminalPost.js b/framework/core/js/forum/src/components/TerminalPost.js index 268e15ab0..c7125104e 100644 --- a/framework/core/js/forum/src/components/TerminalPost.js +++ b/framework/core/js/forum/src/components/TerminalPost.js @@ -1,6 +1,5 @@ import Component from 'flarum/Component'; import humanTime from 'flarum/helpers/humanTime'; -import username from 'flarum/helpers/username'; /** * Displays information about a the first or last post in a discussion. diff --git a/framework/core/js/lib/Model.js b/framework/core/js/lib/Model.js index 343b429dd..736083545 100644 --- a/framework/core/js/lib/Model.js +++ b/framework/core/js/lib/Model.js @@ -227,6 +227,8 @@ export default class Model { return relationship && app.store.getById(relationship.data.type, relationship.data.id); } + + return false; }; } @@ -247,6 +249,8 @@ export default class Model { return relationship && relationship.data.map(data => app.store.getById(data.type, data.id)); } + + return false; }; } diff --git a/framework/core/src/Api/Serializers/Serializer.php b/framework/core/src/Api/Serializers/Serializer.php index 5da1f43ed..559111bcd 100644 --- a/framework/core/src/Api/Serializers/Serializer.php +++ b/framework/core/src/Api/Serializers/Serializer.php @@ -115,7 +115,8 @@ abstract class Serializer extends SerializerAbstract } elseif ($many) { $relationIds = $relation.'_ids'; $data = isset($model->$relationIds) ? $model->$relationIds : $model->$relation()->lists('id'); - } else { + } + if (! $many && empty($data)) { $relationId = $relation.'_id'; $data = $model->$relationId; }