Fix bug and remove unnecessary query

This commit is contained in:
syuilo 2018-05-22 11:45:49 +09:00
parent b414068ada
commit 89dee86f39
2 changed files with 10 additions and 2 deletions

View file

@ -1,6 +1,7 @@
import * as mongo from 'mongodb'; import * as mongo from 'mongodb';
import { default as Notification, INotification } from '../../../models/notification'; import { default as Notification, INotification } from '../../../models/notification';
import publishUserStream from '../../../publishers/stream'; import publishUserStream from '../../../publishers/stream';
import Mute from '../../../models/mute';
/** /**
* Mark as read notification(s) * Mark as read notification(s)
@ -26,6 +27,11 @@ export default (
? [new mongo.ObjectID(message)] ? [new mongo.ObjectID(message)]
: [(message as INotification)._id]; : [(message as INotification)._id];
const mute = await Mute.find({
muterId: userId
});
const mutedUserIds = mute.map(m => m.muteeId);
// Update documents // Update documents
await Notification.update({ await Notification.update({
_id: { $in: ids }, _id: { $in: ids },
@ -42,6 +48,9 @@ export default (
const count = await Notification const count = await Notification
.count({ .count({
notifieeId: userId, notifieeId: userId,
notifierId: {
$nin: mutedUserIds
},
isRead: false isRead: false
}, { }, {
limit: 1 limit: 1

View file

@ -9,8 +9,7 @@ import Mute from '../../../../models/mute';
*/ */
module.exports = (params, user) => new Promise(async (res, rej) => { module.exports = (params, user) => new Promise(async (res, rej) => {
const mute = await Mute.find({ const mute = await Mute.find({
muterId: user._id, muterId: user._id
deletedAt: { $exists: false }
}); });
const mutedUserIds = mute.map(m => m.muteeId); const mutedUserIds = mute.map(m => m.muteeId);