From ede060a64644d9ed79d9fbae0efbafeb5525845a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 13 Jun 2019 10:18:02 -0400 Subject: [PATCH] feat: add hook for user notifications, closes #7672 --- src/notifications.js | 8 ++------ src/user/notifications.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/notifications.js b/src/notifications.js index 27b1fb0439..87b5a79f85 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -63,22 +63,18 @@ Notifications.getMultiple = function (nids, callback) { if (!Array.isArray(nids) || !nids.length) { return setImmediate(callback, null, []); } - var keys = nids.map(function (nid) { - return 'notifications:' + nid; - }); var notifications; async.waterfall([ function (next) { + const keys = nids.map(nid => 'notifications:' + nid); db.getObjects(keys, next); }, function (_notifications, next) { notifications = _notifications; - var userKeys = notifications.map(function (notification) { - return notification && notification.from; - }); + const userKeys = notifications.map(n => n && n.from); User.getUsersFields(userKeys, ['username', 'userslug', 'picture'], next); }, function (usersData, next) { diff --git a/src/user/notifications.js b/src/user/notifications.js index 355dac53a2..c5fd55e2cd 100644 --- a/src/user/notifications.js +++ b/src/user/notifications.js @@ -9,6 +9,7 @@ var db = require('../database'); var meta = require('../meta'); var notifications = require('../notifications'); var privileges = require('../privileges'); +var plugins = require('../plugins'); var utils = require('../utils'); var UserNotifications = module.exports; @@ -111,7 +112,7 @@ function getNotificationsFromSet(set, uid, start, stop, callback) { UserNotifications.getNotifications = function (nids, uid, callback) { if (!Array.isArray(nids) || !nids.length) { - return callback(null, []); + return setImmediate(callback, null, []); } var notificationData = []; @@ -145,6 +146,14 @@ UserNotifications.getNotifications = function (nids, uid, callback) { function (next) { notifications.merge(notificationData, next); }, + function (notifications, next) { + plugins.fireHook('filter:user.notifications.getNotifications', { + uid: uid, + notifications: notifications, + }, function (err, result) { + next(err, result && result.notifications); + }); + }, ], callback); };