From 079a13d41a7b8e063235646f9420d9b83363b8c0 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 24 Feb 2021 12:45:49 -0500 Subject: [PATCH] feat: new hooks for notifications get/getCount --- src/user/notifications.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/user/notifications.js b/src/user/notifications.js index ad9175cab0..a6116c3cb1 100644 --- a/src/user/notifications.js +++ b/src/user/notifications.js @@ -24,10 +24,12 @@ UserNotifications.get = async function (uid) { if (unread.length < 30) { read = await getNotificationsFromSet(`uid:${uid}:notifications:read`, uid, 0, 29 - unread.length); } - return { + + return await plugins.hooks.fire('filter:user.notifications.get', { + uid, read: read.filter(Boolean), unread: unread, - }; + }); }; async function filterNotifications(nids, filter) { @@ -133,7 +135,7 @@ UserNotifications.getUnreadCount = async function (uid) { const mergeIds = notifData.map(n => n.mergeId); // Collapse any notifications with identical mergeIds - return mergeIds.reduce((count, mergeId, idx, arr) => { + let count = mergeIds.reduce((count, mergeId, idx, arr) => { // A missing (null) mergeId means that notification is counted separately. if (mergeId === null || idx === arr.indexOf(mergeId)) { count += 1; @@ -141,6 +143,9 @@ UserNotifications.getUnreadCount = async function (uid) { return count; }, 0); + + ({ count } = await plugins.hooks.fire('filter:user.notifications.getCount', { uid, count })); + return count; }; UserNotifications.getUnreadByField = async function (uid, field, values) {