a bit more integration for #6463

v1.18.x
Julian Lam 7 years ago
parent bfee23adee
commit a367b698e3

@ -39,6 +39,7 @@ module.exports = function (Messaging) {
db.getObjects(keys, next); db.getObjects(keys, next);
}, },
async.apply(user.blocks.filter, uid, 'fromuid'),
function (_messages, next) { function (_messages, next) {
messages = _messages.map(function (msg, idx) { messages = _messages.map(function (msg, idx) {
if (msg) { if (msg) {

@ -17,6 +17,13 @@ module.exports = function (Messaging) {
function (next) { function (next) {
Messaging.getUidsInRoom(roomId, 0, -1, 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) { function (uids, next) {
var data = { var data = {
roomId: roomId, roomId: roomId,

@ -254,6 +254,17 @@ function pushToUids(uids, notification, callback) {
} }
async.waterfall([ 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) { function (next) {
plugins.fireHook('filter:notification.push', { notification: notification, uids: uids }, next); plugins.fireHook('filter:notification.push', { notification: notification, uids: uids }, next);
}, },

@ -52,19 +52,27 @@ module.exports = function (User) {
], callback); ], callback);
}; };
User.blocks.filter = function (uid, set, callback) { User.blocks.filter = function (uid, property, set, callback) {
// Given whatever is passed in, iterates through it, and removes made by blocked uids // property is optional
if (!Array.isArray(set) || !set[0].hasOwnProperty('uid')) { 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); return callback(null, set);
} }
const isPlain = typeof set[0] !== 'object';
User.blocks.list(uid, function (err, blocked_uids) { User.blocks.list(uid, function (err, blocked_uids) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
set = set.filter(function (item) { 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); callback(null, set);

Loading…
Cancel
Save