From 12da13acc5d35489994fa309b84420e03ee19035 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 2 Oct 2015 18:55:23 -0400 Subject: [PATCH] closes #3701 --- src/socket.io/helpers.js | 113 ++++++++++++++++++++++++++++++ src/socket.io/posts.js | 74 +------------------ src/socket.io/posts/favourites.js | 3 +- src/socket.io/posts/move.js | 4 +- src/socket.io/topics.js | 33 --------- src/socket.io/topics/move.js | 5 +- src/socket.io/topics/tools.js | 3 +- 7 files changed, 125 insertions(+), 110 deletions(-) create mode 100644 src/socket.io/helpers.js 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