34 lines
608 B
TypeScript
34 lines
608 B
TypeScript
/**
|
|
* Module dependencies
|
|
*/
|
|
import Message from '../../models/messaging-message';
|
|
import Mute from '../../models/mute';
|
|
|
|
/**
|
|
* Get count of unread messages
|
|
*
|
|
* @param {any} params
|
|
* @param {any} user
|
|
* @return {Promise<any>}
|
|
*/
|
|
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 Message
|
|
.count({
|
|
userId: {
|
|
$nin: mutedUserIds
|
|
},
|
|
recipientId: user._id,
|
|
isRead: false
|
|
});
|
|
|
|
res({
|
|
count: count
|
|
});
|
|
});
|