mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: add hook for user notifications, closes #7672
This commit is contained in:
@@ -63,22 +63,18 @@ Notifications.getMultiple = function (nids, callback) {
|
|||||||
if (!Array.isArray(nids) || !nids.length) {
|
if (!Array.isArray(nids) || !nids.length) {
|
||||||
return setImmediate(callback, null, []);
|
return setImmediate(callback, null, []);
|
||||||
}
|
}
|
||||||
var keys = nids.map(function (nid) {
|
|
||||||
return 'notifications:' + nid;
|
|
||||||
});
|
|
||||||
|
|
||||||
var notifications;
|
var notifications;
|
||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
|
const keys = nids.map(nid => 'notifications:' + nid);
|
||||||
db.getObjects(keys, next);
|
db.getObjects(keys, next);
|
||||||
},
|
},
|
||||||
function (_notifications, next) {
|
function (_notifications, next) {
|
||||||
notifications = _notifications;
|
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);
|
User.getUsersFields(userKeys, ['username', 'userslug', 'picture'], next);
|
||||||
},
|
},
|
||||||
function (usersData, next) {
|
function (usersData, next) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ var db = require('../database');
|
|||||||
var meta = require('../meta');
|
var meta = require('../meta');
|
||||||
var notifications = require('../notifications');
|
var notifications = require('../notifications');
|
||||||
var privileges = require('../privileges');
|
var privileges = require('../privileges');
|
||||||
|
var plugins = require('../plugins');
|
||||||
var utils = require('../utils');
|
var utils = require('../utils');
|
||||||
|
|
||||||
var UserNotifications = module.exports;
|
var UserNotifications = module.exports;
|
||||||
@@ -111,7 +112,7 @@ function getNotificationsFromSet(set, uid, start, stop, callback) {
|
|||||||
|
|
||||||
UserNotifications.getNotifications = function (nids, uid, callback) {
|
UserNotifications.getNotifications = function (nids, uid, callback) {
|
||||||
if (!Array.isArray(nids) || !nids.length) {
|
if (!Array.isArray(nids) || !nids.length) {
|
||||||
return callback(null, []);
|
return setImmediate(callback, null, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
var notificationData = [];
|
var notificationData = [];
|
||||||
@@ -145,6 +146,14 @@ UserNotifications.getNotifications = function (nids, uid, callback) {
|
|||||||
function (next) {
|
function (next) {
|
||||||
notifications.merge(notificationData, 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);
|
], callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user