diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-05-22 11:45:49 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-05-22 11:45:49 +0900 |
| commit | 89dee86f3917a13d27043c0b744cd5b9f9ef93b9 (patch) | |
| tree | de843bbfe0098637225faa2c40f4b512992be61d /src | |
| parent | Refactor (diff) | |
| download | sharkey-89dee86f3917a13d27043c0b744cd5b9f9ef93b9.tar.gz sharkey-89dee86f3917a13d27043c0b744cd5b9f9ef93b9.tar.bz2 sharkey-89dee86f3917a13d27043c0b744cd5b9f9ef93b9.zip | |
Fix bug and remove unnecessary query
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/api/common/read-notification.ts | 9 | ||||
| -rw-r--r-- | src/server/api/endpoints/notifications/get_unread_count.ts | 3 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/server/api/common/read-notification.ts b/src/server/api/common/read-notification.ts index 7b9faf4cf4..cdb87a4114 100644 --- a/src/server/api/common/read-notification.ts +++ b/src/server/api/common/read-notification.ts @@ -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 diff --git a/src/server/api/endpoints/notifications/get_unread_count.ts b/src/server/api/endpoints/notifications/get_unread_count.ts index 600a80d194..9766366ff1 100644 --- a/src/server/api/endpoints/notifications/get_unread_count.ts +++ b/src/server/api/endpoints/notifications/get_unread_count.ts @@ -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); |