mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-03 12:36:02 +01:00
a bit more integration for #6463
This commit is contained in:
@@ -39,6 +39,7 @@ module.exports = function (Messaging) {
|
||||
|
||||
db.getObjects(keys, next);
|
||||
},
|
||||
async.apply(user.blocks.filter, uid, 'fromuid'),
|
||||
function (_messages, next) {
|
||||
messages = _messages.map(function (msg, idx) {
|
||||
if (msg) {
|
||||
|
||||
@@ -17,6 +17,13 @@ module.exports = function (Messaging) {
|
||||
function (next) {
|
||||
Messaging.getUidsInRoom(roomId, 0, -1, next);
|
||||
},
|
||||
function (uids, next) {
|
||||
async.filter(uids, function (uid, next) {
|
||||
user.blocks.is(fromUid, uid, function (err, blocked) {
|
||||
next(err, !blocked);
|
||||
});
|
||||
}, next);
|
||||
},
|
||||
function (uids, next) {
|
||||
var data = {
|
||||
roomId: roomId,
|
||||
|
||||
@@ -254,6 +254,17 @@ function pushToUids(uids, notification, callback) {
|
||||
}
|
||||
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
// Remove uid from recipients list if they have blocked the user triggering the notification
|
||||
async.filter(uids, function (uid, next) {
|
||||
User.blocks.is(notification.from, uid, function (err, blocked) {
|
||||
next(err, !blocked);
|
||||
});
|
||||
}, function (err, _uids) {
|
||||
uids = _uids;
|
||||
next(err);
|
||||
});
|
||||
},
|
||||
function (next) {
|
||||
plugins.fireHook('filter:notification.push', { notification: notification, uids: uids }, next);
|
||||
},
|
||||
|
||||
@@ -52,19 +52,27 @@ module.exports = function (User) {
|
||||
], callback);
|
||||
};
|
||||
|
||||
User.blocks.filter = function (uid, set, callback) {
|
||||
// Given whatever is passed in, iterates through it, and removes made by blocked uids
|
||||
if (!Array.isArray(set) || !set[0].hasOwnProperty('uid')) {
|
||||
User.blocks.filter = function (uid, property, set, callback) {
|
||||
// property is optional
|
||||
if (Array.isArray(property) && typeof set === 'function' && !callback) {
|
||||
callback = set;
|
||||
set = property;
|
||||
property = 'uid';
|
||||
}
|
||||
|
||||
// Given whatever is passed in, iterates through it, and removes entries made by blocked uids
|
||||
if (!Array.isArray(set) || !(set[0].hasOwnProperty(property) || typeof set[0] === 'number' || typeof set[0] === 'string')) {
|
||||
return callback(null, set);
|
||||
}
|
||||
|
||||
const isPlain = typeof set[0] !== 'object';
|
||||
User.blocks.list(uid, function (err, blocked_uids) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
set = set.filter(function (item) {
|
||||
return !blocked_uids.includes(parseInt(item.uid, 10));
|
||||
return !blocked_uids.includes(parseInt(isPlain ? item : item[property], 10));
|
||||
});
|
||||
|
||||
callback(null, set);
|
||||
|
||||
Reference in New Issue
Block a user