Skip to content

Node.js based forum software built for the modern web

closes #6514

Barış Soner Uşaklı7a1888dfbfc0
diff --git a/src/messaging/create.js b/src/messaging/create.js
index 6f355a9ff8..252989e5c7 100644
--- a/src/messaging/create.js
+++ b/src/messaging/create.js
@@ -5,7 +5,7 @@ var async = require('async');
var meta = require('../meta');
var plugins = require('../plugins');
var db = require('../database');
-
+var user = require('../user');
module.exports = function (Messaging) {
Messaging.sendMessage = function (uid, roomId, content, timestamp, callback) {
@@ -73,6 +73,9 @@ module.exports = function (Messaging) {
isNewSet = _isNewSet;
db.getSortedSetRange('chat:room:' + roomId + ':uids', 0, -1, next);
},
+ function (uids, next) {
+ user.blocks.filterUids(fromuid, uids, next);
+ },
function (uids, next) {
async.parallel([
async.apply(Messaging.addRoomToUsers, roomId, uids, timestamp),
diff --git a/src/messaging/notifications.js b/src/messaging/notifications.js
index 8dd01a14fe..340ddcf356 100644
--- a/src/messaging/notifications.js
+++ b/src/messaging/notifications.js
@@ -18,11 +18,7 @@ module.exports = function (Messaging) {
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);
+ user.blocks.filterUids(fromUid, uids, next);
},
function (uids, next) {
var data = {
diff --git a/src/notifications.js b/src/notifications.js
index 30089a2d1d..32adb67fe3 100644
--- a/src/notifications.js
+++ b/src/notifications.js
@@ -286,16 +286,9 @@ 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);
- });
+ User.blocks.filterUids(notification.from, uids, next);
},
- function (next) {
+ function (uids, next) {
plugins.fireHook('filter:notification.push', { notification: notification, uids: uids }, next);
},
function (data, next) {
diff --git a/src/user/blocks.js b/src/user/blocks.js
index 5fd8977874..75767e4a12 100644
--- a/src/user/blocks.js
+++ b/src/user/blocks.js
@@ -76,6 +76,14 @@ module.exports = function (User) {
});
};
+ User.blocks.filterUids = function (targetUid, uids, callback) {
+ async.filter(uids, function (uid, next) {
+ User.blocks.is(targetUid, uid, function (err, blocked) {
+ next(err, !blocked);
+ });
+ }, callback);
+ };
+
User.blocks.filter = function (uid, property, set, callback) {
// Given whatever is passed in, iterates through it, and removes entries made by blocked uids
// property is optional