2017-10-30 22:12:10 +09:00
|
|
|
/**
|
|
|
|
|
* Module dependencies
|
|
|
|
|
*/
|
2018-03-29 20:32:18 +09:00
|
|
|
import Notification from '../../../../models/notification';
|
|
|
|
|
import Mute from '../../../../models/mute';
|
2017-10-30 22:12:10 +09:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get count of unread notifications
|
|
|
|
|
*/
|
|
|
|
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
2017-12-22 07:38:57 +09:00
|
|
|
const mute = await Mute.find({
|
2018-03-29 14:48:47 +09:00
|
|
|
muterId: user._id,
|
|
|
|
|
deletedAt: { $exists: false }
|
2017-12-22 07:38:57 +09:00
|
|
|
});
|
2018-03-29 14:48:47 +09:00
|
|
|
const mutedUserIds = mute.map(m => m.muteeId);
|
2017-12-22 07:38:57 +09:00
|
|
|
|
2017-10-30 22:12:10 +09:00
|
|
|
const count = await Notification
|
|
|
|
|
.count({
|
2018-03-29 14:48:47 +09:00
|
|
|
notifieeId: user._id,
|
|
|
|
|
notifierId: {
|
2017-12-22 07:38:57 +09:00
|
|
|
$nin: mutedUserIds
|
|
|
|
|
},
|
2018-03-29 14:48:47 +09:00
|
|
|
isRead: false
|
2017-10-30 22:12:10 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
res({
|
|
|
|
|
count: count
|
|
|
|
|
});
|
|
|
|
|
});
|