summaryrefslogtreecommitdiff
path: root/src/server/api/endpoints/notifications/get_unread_count.ts
blob: 600a80d1942ee6919696e956aeacea994241d247 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
 * Module dependencies
 */
import Notification from '../../../../models/notification';
import Mute from '../../../../models/mute';

/**
 * Get count of unread notifications
 */
module.exports = (params, user) => new Promise(async (res, rej) => {
	const mute = await Mute.find({
		muterId: user._id,
		deletedAt: { $exists: false }
	});
	const mutedUserIds = mute.map(m => m.muteeId);

	const count = await Notification
		.count({
			notifieeId: user._id,
			notifierId: {
				$nin: mutedUserIds
			},
			isRead: false
		});

	res({
		count: count
	});
});