Skip to content

Node.js based forum software built for the modern web

a bit more integration for #6463

Julian Lama367b698e357
diff --git a/src/messaging/data.js b/src/messaging/data.js
index bae9c6deac..aa269d19c9 100644
--- a/src/messaging/data.js
+++ b/src/messaging/data.js
@@ -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) {
diff --git a/src/messaging/notifications.js b/src/messaging/notifications.js
index 6e5d6a2ce8..8dd01a14fe 100644
--- a/src/messaging/notifications.js
+++ b/src/messaging/notifications.js
@@ -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,
diff --git a/src/notifications.js b/src/notifications.js
index 8a91c44509..e828195fec 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -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);
},
diff --git a/src/user/blocks.js b/src/user/blocks.js
index b1682ed83f..7cd2f1da76 100644
--- a/src/user/blocks.js
+++ b/src/user/blocks.js
@@ -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);