diff --git a/src/socket.io/helpers.js b/src/socket.io/helpers.js new file mode 100644 index 0000000000..c538aca14d --- /dev/null +++ b/src/socket.io/helpers.js @@ -0,0 +1,113 @@ +'use strict'; + +var async = require('async'); +var winston = require('winston'); +var nconf = require('nconf'); + +var websockets = require('./index'); +var user = require('../user'); +var posts = require('../posts'); +var topics = require('../topics'); +var privileges = require('../privileges'); +var notifications = require('../notifications'); +var plugins = require('../plugins'); + +var SocketHelpers = {}; + +SocketHelpers.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; + + for(var i=0; i