mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
notifications: fixes
This commit is contained in:
@@ -4,6 +4,9 @@ import moment from 'moment';
|
||||
import Bluebird from 'bluebird';
|
||||
import baseModel from '../../libs/baseModel';
|
||||
import * as Tasks from '../task';
|
||||
import {
|
||||
model as UserNotification,
|
||||
} from '../userNotification';
|
||||
|
||||
import schema from './schema';
|
||||
|
||||
@@ -15,6 +18,8 @@ schema.plugin(baseModel, {
|
||||
plainObj._tmp = originalDoc._tmp; // be sure to send down drop notifs
|
||||
delete plainObj.filters;
|
||||
|
||||
plainObj.notifications = UserNotification.convertNotificationsToSafeJson(originalDoc.notifications);
|
||||
|
||||
return plainObj;
|
||||
},
|
||||
});
|
||||
@@ -255,7 +260,7 @@ schema.pre('save', true, function preSaveUser (next, done) {
|
||||
|
||||
// Sometimes there can be more than 1 notification
|
||||
const existingNotifications = this.notifications.filter(notification => {
|
||||
return notification.type === 'UNALLOCATED_STATS_POINTS';
|
||||
return notification && notification.type === 'UNALLOCATED_STATS_POINTS';
|
||||
});
|
||||
|
||||
const existingNotificationsLength = existingNotifications.length;
|
||||
@@ -277,7 +282,7 @@ schema.pre('save', true, function preSaveUser (next, done) {
|
||||
let notificationsRemoved = 0;
|
||||
|
||||
this.notifications = this.notifications.filter(notification => {
|
||||
if (notification.type !== 'UNALLOCATED_STATS_POINTS') return true;
|
||||
if (notification && notification.type !== 'UNALLOCATED_STATS_POINTS') return true;
|
||||
if (notificationsRemoved === notificationsToRemove) return true;
|
||||
|
||||
notificationsRemoved++;
|
||||
|
||||
Reference in New Issue
Block a user