From ab16fb3a3fff96a4fa2bc1fc0e56a87c129a4625 Mon Sep 17 00:00:00 2001 From: syuilo Date: Tue, 29 May 2018 01:22:39 +0900 Subject: #1634 --- .../endpoints/notifications/get_unread_count.ts | 28 ---------------------- .../endpoints/notifications/mark_as_read_all.ts | 11 ++++++--- 2 files changed, 8 insertions(+), 31 deletions(-) delete mode 100644 src/server/api/endpoints/notifications/get_unread_count.ts (limited to 'src/server/api/endpoints/notifications') diff --git a/src/server/api/endpoints/notifications/get_unread_count.ts b/src/server/api/endpoints/notifications/get_unread_count.ts deleted file mode 100644 index 9766366ff1..0000000000 --- a/src/server/api/endpoints/notifications/get_unread_count.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Module dependencies - */ -import Notification from '../../../../models/notification'; -import Mute from '../../../../models/mute'; - -/** - * Get count of unread notifications - */ -module.exports = (params, user) => new Promise(async (res, rej) => { - const mute = await Mute.find({ - muterId: user._id - }); - const mutedUserIds = mute.map(m => m.muteeId); - - const count = await Notification - .count({ - notifieeId: user._id, - notifierId: { - $nin: mutedUserIds - }, - isRead: false - }); - - res({ - count: count - }); -}); diff --git a/src/server/api/endpoints/notifications/mark_as_read_all.ts b/src/server/api/endpoints/notifications/mark_as_read_all.ts index dce3cb4663..7a48ca3e62 100644 --- a/src/server/api/endpoints/notifications/mark_as_read_all.ts +++ b/src/server/api/endpoints/notifications/mark_as_read_all.ts @@ -1,8 +1,6 @@ -/** - * Module dependencies - */ import Notification from '../../../../models/notification'; import event from '../../../../publishers/stream'; +import User from '../../../../models/user'; /** * Mark as read all notifications @@ -23,6 +21,13 @@ module.exports = (params, user) => new Promise(async (res, rej) => { // Response res(); + // Update flag + User.update({ _id: user._id }, { + $set: { + hasUnreadNotification: false + } + }); + // 全ての通知を読みましたよというイベントを発行 event(user._id, 'read_all_notifications'); }); -- cgit v1.2.3-freya