mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
prevent multiple notifications (#10524)
* WIP - prevent multiple notifications * merge promises to one * update test, iterate each user * revert changes in `groups.js` - filter duplicate notifications in `convertNotificationsToSafeJson`
This commit is contained in:
@@ -2,6 +2,7 @@ import mongoose from 'mongoose';
|
||||
import baseModel from '../libs/baseModel';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import validator from 'validator';
|
||||
import _ from 'lodash';
|
||||
|
||||
const NOTIFICATION_TYPES = [
|
||||
'DROPS_ENABLED',
|
||||
@@ -74,13 +75,22 @@ export let schema = new Schema({
|
||||
schema.statics.convertNotificationsToSafeJson = function convertNotificationsToSafeJson (notifications) {
|
||||
if (!notifications) return notifications;
|
||||
|
||||
return notifications.filter(n => {
|
||||
let filteredNotifications = notifications.filter(n => {
|
||||
// Exclude notifications with a nullish value
|
||||
if (!n) return false;
|
||||
// Exclude notifications without an id or a type
|
||||
if (!n.id || !n.type) return false;
|
||||
return true;
|
||||
}).map(n => {
|
||||
});
|
||||
|
||||
filteredNotifications = _.uniqWith(filteredNotifications, (val, otherVal) => {
|
||||
if (val.type === otherVal.type && val.type === 'NEW_CHAT_MESSAGE') {
|
||||
return val.data.group.id === otherVal.data.group.id;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
return filteredNotifications.map(n => {
|
||||
return n.toJSON();
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user