1
0
mirror of https://github.com/hotomoe/hotomoe synced 2024-11-25 07:36:24 +09:00

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 { 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

View File

@ -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);