Skip to content
Snippets Groups Projects
Commit 89dee86f authored by syuilo's avatar syuilo
Browse files

Fix bug and remove unnecessary query

parent b414068a
No related branches found
No related tags found
No related merge requests found
import * as mongo from 'mongodb';
import { default as Notification, INotification } from '../../../models/notification';
import publishUserStream from '../../../publishers/stream';
import Mute from '../../../models/mute';
/**
* Mark as read notification(s)
......@@ -26,6 +27,11 @@ export default (
? [new mongo.ObjectID(message)]
: [(message as INotification)._id];
const mute = await Mute.find({
muterId: userId
});
const mutedUserIds = mute.map(m => m.muteeId);
// Update documents
await Notification.update({
_id: { $in: ids },
......@@ -42,6 +48,9 @@ export default (
const count = await Notification
.count({
notifieeId: userId,
notifierId: {
$nin: mutedUserIds
},
isRead: false
}, {
limit: 1
......
......@@ -9,8 +9,7 @@ import Mute from '../../../../models/mute';
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
const mute = await Mute.find({
muterId: user._id,
deletedAt: { $exists: false }
muterId: user._id
});
const mutedUserIds = mute.map(m => m.muteeId);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment