diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index 71e5577178..d0f5b3b589 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -47,29 +47,34 @@ SocketPosts.reply = function(socket, data, callback) { socket.emit('event:new_post', result); - async.waterfall([ - function(next) { - user.getUidsFromSet('users:online', 0, -1, next); - }, - function(uids, next) { - privileges.categories.filterUids('read', postData.topic.cid, uids, next); - }, - function(uids, next) { - plugins.fireHook('filter:sockets.sendNewPostToUids', {uidsTo: uids, uidFrom: data.uid, type: 'newPost'}, next); - } - ], function(err, data) { - if (err) { - return winston.error(err.stack); - } + SocketPosts.notifyOnlineUsers(socket.uid, result); + }); +}; + +SocketPosts.notifyOnlineUsers = function(uid, result) { + var cid = result.posts[0].topic.cid; + async.waterfall([ + function(next) { + user.getUidsFromSet('users:online', 0, -1, next); + }, + function(uids, next) { + privileges.categories.filterUids('read', cid, uids, next); + }, + function(uids, next) { + plugins.fireHook('filter:sockets.sendNewPostToUids', {uidsTo: uids, uidFrom: uid, type: 'newPost'}, next); + } + ], function(err, data) { + if (err) { + return winston.error(err.stack); + } - var uids = data.uidsTo; + var uids = data.uidsTo; - for(var i=0; i