import Component from 'flarum/Component'; import listItems from 'flarum/helpers/listItems'; import Button from 'flarum/components/Button'; import LoadingIndicator from 'flarum/components/LoadingIndicator'; import Discussion from 'flarum/models/Discussion'; /** * The `NotificationList` component displays a list of the logged-in user's * notifications, grouped by discussion. */ export default class NotificationList extends Component { constructor(...args) { super(...args); /** * Whether or not the notifications are loading. * * @type {Boolean} */ this.loading = false; } view() { const groups = []; if (app.cache.notifications) { const discussions = {}; // Build an array of discussions which the notifications are related to, // and add the notifications as children. 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 = false; if (subject instanceof Discussion) discussion = subject; 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. const key = discussion ? discussion.id() : 0; discussions[key] = discussions[key] || {discussion: discussion, notifications: []}; discussions[key].notifications.push(notification); if (groups.indexOf(discussions[key]) === -1) { groups.push(discussions[key]); } }); } return (