removed global.io

v1.18.x
Baris Soner Usakli 12 years ago
parent f616125d02
commit 32b191fa62

@ -72,6 +72,7 @@ define(['forum/accountheader'], function(header) {
socket.on('event:new_post', function(data) { socket.on('event:new_post', function(data) {
var html = templates.prepare(templates['account'].blocks['posts']).parse(data); var html = templates.prepare(templates['account'].blocks['posts']).parse(data);
$('.user-recent-posts').prepend(html); $('.user-recent-posts').prepend(html);
$('.user-recent-posts span.timeago').timeago();
}); });
}); });

@ -139,7 +139,7 @@
}); });
socket.on('event:new_notification', function() { socket.on('event:new_notification', function() {
document.querySelector('.notifications a i').className = 'fa-circle active'; document.querySelector('.notifications a i').className = 'fa fa-circle active';
app.alert({ app.alert({
alert_id: 'new_notif', alert_id: 'new_notif',
title: 'New notification', title: 'New notification',

@ -143,7 +143,13 @@ var RDB = require('./redis.js'),
Categories.getAllCategories = function(current_user, callback) { Categories.getAllCategories = function(current_user, callback) {
RDB.lrange('categories:cid', 0, -1, function(err, cids) { RDB.lrange('categories:cid', 0, -1, function(err, cids) {
RDB.handle(err); if(err) {
return callback(err);
}
if(cids && cids.length === 0) {
return callback(null, {categories : []});
}
Categories.getCategories(cids, current_user, callback); Categories.getCategories(cids, current_user, callback);
}); });
}; };

@ -1,7 +1,8 @@
var RDB = require('./redis.js'), var RDB = require('./redis'),
posts = require('./posts.js'), posts = require('./posts'),
user = require('./user.js'), user = require('./user'),
translator = require('./../public/src/translator.js'); websockets = require('./websockets')
translator = require('./../public/src/translator');
(function (Favourites) { (function (Favourites) {
"use strict"; "use strict";
@ -37,7 +38,7 @@ var RDB = require('./redis.js'),
} }
if (room_id) { if (room_id) {
io.sockets. in (room_id).emit('event:rep_up', { websockets.in(room_id).emit('event:rep_up', {
uid: uid !== postData.uid ? postData.uid : 0, uid: uid !== postData.uid ? postData.uid : 0,
pid: pid pid: pid
}); });
@ -72,7 +73,7 @@ var RDB = require('./redis.js'),
} }
if (room_id) { if (room_id) {
io.sockets. in (room_id).emit('event:rep_down', { websockets.in(room_id).emit('event:rep_down', {
uid: uid !== uid_of_poster ? uid_of_poster : 0, uid: uid !== uid_of_poster ? uid_of_poster : 0,
pid: pid pid: pid
}); });

@ -4,148 +4,155 @@ var RDB = require('./redis'),
winston = require('winston'), winston = require('winston'),
cron = require('cron').CronJob, cron = require('cron').CronJob,
notifications = { websockets = require('./websockets');
init: function() {
if (process.env.NODE_ENV === 'development') {
winston.info('[notifications.init] Registering jobs.');
}
new cron('0 0 * * *', notifications.prune, null, true);
},
get: function(nid, uid, callback) {
RDB.multi()
.hmget('notifications:' + nid, 'text', 'score', 'path', 'datetime', 'uniqueId')
.zrank('uid:' + uid + ':notifications:read', nid)
.exists('notifications:' + nid)
.exec(function(err, results) {
var notification = results[0],
readIdx = results[1];
if (!results[2]) {
return callback(null);
}
callback({
nid: nid, (function(Notifications) {
text: notification[0],
score: notification[1], Notifications.init = function() {
path: notification[2], if (process.env.NODE_ENV === 'development') {
datetime: notification[3], winston.info('[notifications.init] Registering jobs.');
uniqueId: notification[4], }
read: readIdx !== null ? true : false new cron('0 0 * * *', Notifications.prune, null, true);
}); };
});
}, Notifications.get = function(nid, uid, callback) {
create: function(text, path, uniqueId, callback) { RDB.multi()
/** .hmget('notifications:' + nid, 'text', 'score', 'path', 'datetime', 'uniqueId')
* uniqueId is used solely to override stale nids. .zrank('uid:' + uid + ':notifications:read', nid)
* If a new nid is pushed to a user and an existing nid in the user's .exists('notifications:' + nid)
* (un)read list contains the same uniqueId, it will be removed, and .exec(function(err, results) {
* the new one put in its place. var notification = results[0],
*/ readIdx = results[1];
RDB.incr('notifications:next_nid', function(err, nid) {
RDB.sadd('notifications', nid); if (!results[2]) {
RDB.hmset('notifications:' + nid, { return callback(null);
text: text || '', }
path: path || null,
datetime: Date.now(), callback({
uniqueId: uniqueId || utils.generateUUID() nid: nid,
}, function(err, status) { text: notification[0],
if (!err) { score: notification[1],
callback(nid); path: notification[2],
} datetime: notification[3],
uniqueId: notification[4],
read: readIdx !== null ? true : false
}); });
}); });
}, };
destroy: function(nid) {
var multi = RDB.multi();
multi.del('notifications:' + nid);
multi.srem('notifications', nid);
multi.exec(function(err) { Notifications.create = function(text, path, uniqueId, callback) {
if (err) { /**
winston.error('Problem deleting expired notifications. Stack follows.'); * uniqueId is used solely to override stale nids.
winston.error(err.stack); * If a new nid is pushed to a user and an existing nid in the user's
* (un)read list contains the same uniqueId, it will be removed, and
* the new one put in its place.
*/
RDB.incr('notifications:next_nid', function(err, nid) {
RDB.sadd('notifications', nid);
RDB.hmset('notifications:' + nid, {
text: text || '',
path: path || null,
datetime: Date.now(),
uniqueId: uniqueId || utils.generateUUID()
}, function(err, status) {
if (!err) {
callback(nid);
} }
}); });
}, });
push: function(nid, uids, callback) { };
if (!Array.isArray(uids)) uids = [uids];
var numUids = uids.length, function destroy(nid) {
x; var multi = RDB.multi();
notifications.get(nid, null, function(notif_data) { multi.del('notifications:' + nid);
for (x = 0; x < numUids; x++) { multi.srem('notifications', nid);
if (parseInt(uids[x], 10) > 0) {
(function(uid) {
notifications.remove_by_uniqueId(notif_data.uniqueId, uid, function() {
RDB.zadd('uid:' + uid + ':notifications:unread', notif_data.datetime, nid);
global.io.sockets.in('uid_' + uid).emit('event:new_notification'); multi.exec(function(err) {
if (err) {
winston.error('Problem deleting expired notifications. Stack follows.');
winston.error(err.stack);
}
});
}
// TODO: moving this require to the top of the file overwrites 'notifications' figure out why -baris Notifications.push = function(nid, uids, callback) {
//require('./websockets').in('uid_' + uid).emit('event:new_notification'); if (!Array.isArray(uids)) uids = [uids];
if (callback) { var numUids = uids.length,
callback(true); x;
}
}); Notifications.get(nid, null, function(notif_data) {
})(uids[x]); for (x = 0; x < numUids; x++) {
} if (parseInt(uids[x], 10) > 0) {
(function(uid) {
remove_by_uniqueId(notif_data.uniqueId, uid, function() {
RDB.zadd('uid:' + uid + ':notifications:unread', notif_data.datetime, nid);
websockets.in('uid_' + uid).emit('event:new_notification');
if (callback) {
callback(true);
}
});
})(uids[x]);
} }
}); }
}, });
remove_by_uniqueId: function(uniqueId, uid, callback) { };
async.parallel([
function(next) { function remove_by_uniqueId(uniqueId, uid, callback) {
RDB.zrange('uid:' + uid + ':notifications:unread', 0, -1, function(err, nids) { async.parallel([
if (nids && nids.length > 0) { function(next) {
async.each(nids, function(nid, next) { RDB.zrange('uid:' + uid + ':notifications:unread', 0, -1, function(err, nids) {
notifications.get(nid, uid, function(nid_info) { if (nids && nids.length > 0) {
if (nid_info.uniqueId === uniqueId) { async.each(nids, function(nid, next) {
RDB.zrem('uid:' + uid + ':notifications:unread', nid); Notifications.get(nid, uid, function(nid_info) {
} if (nid_info.uniqueId === uniqueId) {
RDB.zrem('uid:' + uid + ':notifications:unread', nid);
next(); }
});
}, function(err) {
next(); next();
}); });
} else { }, function(err) {
next(); next();
} });
}); } else {
}, next();
function(next) { }
RDB.zrange('uid:' + uid + ':notifications:read', 0, -1, function(err, nids) { });
if (nids && nids.length > 0) { },
async.each(nids, function(nid, next) { function(next) {
notifications.get(nid, uid, function(nid_info) { RDB.zrange('uid:' + uid + ':notifications:read', 0, -1, function(err, nids) {
if (nid_info && nid_info.uniqueId === uniqueId) { if (nids && nids.length > 0) {
RDB.zrem('uid:' + uid + ':notifications:read', nid); async.each(nids, function(nid, next) {
} Notifications.get(nid, uid, function(nid_info) {
if (nid_info && nid_info.uniqueId === uniqueId) {
next(); RDB.zrem('uid:' + uid + ':notifications:read', nid);
}); }
}, function(err) {
next(); next();
}); });
} else { }, function(err) {
next(); next();
} });
}); } else {
} next();
], function(err) { }
if (!err) { });
callback(true); }
} ], function(err) {
}); if (!err) {
}, callback(true);
mark_read: function(nid, uid, callback) { }
});
}
Notifications.mark_read = function(nid, uid, callback) {
if (parseInt(uid) > 0) { if (parseInt(uid) > 0) {
notifications.get(nid, uid, function(notif_data) { Notifications.get(nid, uid, function(notif_data) {
RDB.zrem('uid:' + uid + ':notifications:unread', nid); RDB.zrem('uid:' + uid + ':notifications:unread', nid);
RDB.zadd('uid:' + uid + ':notifications:read', notif_data.datetime, nid); RDB.zadd('uid:' + uid + ':notifications:read', notif_data.datetime, nid);
if (callback) { if (callback) {
@ -153,121 +160,115 @@ var RDB = require('./redis'),
} }
}); });
} }
}, }
mark_read_multiple: function(nids, uid, callback) {
if (!Array.isArray(nids) && parseInt(nids, 10) > 0) {
nids = [nids];
}
async.each(nids, function(nid, next) { Notifications.mark_read_multiple = function(nids, uid, callback) {
notifications.mark_read(nid, uid, function(err) { if (!Array.isArray(nids) && parseInt(nids, 10) > 0) {
if (!err) { nids = [nids];
next(null); }
}
});
}, function(err) {
if (callback) {
callback(err);
}
});
},
mark_all_read: function(uid, callback) {
RDB.zrange('uid:' + uid + ':notifications:unread', 0, 10, function(err, nids) {
if (err) {
return callback(err);
}
if (nids.length > 0) { async.each(nids, function(nid, next) {
notifications.mark_read_multiple(nids, uid, function(err) { Notifications.mark_read(nid, uid, function(err) {
callback(err); if (!err) {
}); next(null);
} else {
callback();
} }
}); });
}, }, function(err) {
prune: function(cutoff) { if (callback) {
if (process.env.NODE_ENV === 'development') { callback(err);
winston.info('[notifications.prune] Removing expired notifications from the database.');
} }
});
};
var today = new Date(), Notifications.mark_all_read = function(uid, callback) {
numPruned = 0; RDB.zrange('uid:' + uid + ':notifications:unread', 0, 10, function(err, nids) {
if (err) {
return callback(err);
}
if (!cutoff) { if (nids.length > 0) {
cutoff = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7); Notifications.mark_read_multiple(nids, uid, function(err) {
callback(err);
});
} else {
callback();
} }
});
};
var cutoffTime = cutoff.getTime(); Notifications.prune = function(cutoff) {
if (process.env.NODE_ENV === 'development') {
async.parallel({ winston.info('[notifications.prune] Removing expired notifications from the database.');
"inboxes": function(next) { }
RDB.keys('uid:*:notifications:unread', next);
}, var today = new Date(),
"nids": function(next) { numPruned = 0;
RDB.smembers('notifications', function(err, nids) {
async.filter(nids, function(nid, next) { if (!cutoff) {
RDB.hget('notifications:' + nid, 'datetime', function(err, datetime) { cutoff = new Date(today.getFullYear(), today.getMonth(), today.getDate() - 7);
if (parseInt(datetime, 10) < cutoffTime) { }
next(true);
} else { var cutoffTime = cutoff.getTime();
next(false);
} async.parallel({
}); "inboxes": function(next) {
}, function(expiredNids) { RDB.keys('uid:*:notifications:unread', next);
next(null, expiredNids); },
"nids": function(next) {
RDB.smembers('notifications', function(err, nids) {
async.filter(nids, function(nid, next) {
RDB.hget('notifications:' + nid, 'datetime', function(err, datetime) {
if (parseInt(datetime, 10) < cutoffTime) {
next(true);
} else {
next(false);
}
}); });
}, function(expiredNids) {
next(null, expiredNids);
}); });
} });
}, function(err, results) { }
if (!err) { }, function(err, results) {
var numInboxes = results.inboxes.length, if (!err) {
x; var numInboxes = results.inboxes.length,
x;
async.eachSeries(results.nids, function(nid, next) { async.eachSeries(results.nids, function(nid, next) {
var multi = RDB.multi(); var multi = RDB.multi();
for(x=0;x<numInboxes;x++) { for(x=0;x<numInboxes;x++) {
multi.zscore(results.inboxes[x], nid); multi.zscore(results.inboxes[x], nid);
} }
multi.exec(function(err, results) { multi.exec(function(err, results) {
// If the notification is not present in any inbox, delete it altogether // If the notification is not present in any inbox, delete it altogether
var expired = results.every(function(present) { var expired = results.every(function(present) {
if (present === null) { if (present === null) {
return true; return true;
} }
}); });
if (expired) {
notifications.destroy(nid);
numPruned++;
}
next(); if (expired) {
}); destroy(nid);
}, function(err) { numPruned++;
if (process.env.NODE_ENV === 'development') {
winston.info('[notifications.prune] Notification pruning completed. ' + numPruned + ' expired notification' + (numPruned !== 1 ? 's' : '') + ' removed.');
} }
next();
}); });
} else { }, function(err) {
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
winston.error('[notifications.prune] Ran into trouble pruning expired notifications. Stack trace to follow.'); winston.info('[notifications.prune] Notification pruning completed. ' + numPruned + ' expired notification' + (numPruned !== 1 ? 's' : '') + ' removed.');
winston.error(err.stack);
} }
});
} else {
if (process.env.NODE_ENV === 'development') {
winston.error('[notifications.prune] Ran into trouble pruning expired notifications. Stack trace to follow.');
winston.error(err.stack);
} }
}); }
});
}
}; };
module.exports = { }(exports));
init: notifications.init,
get: notifications.get,
create: notifications.create,
push: notifications.push,
mark_read: notifications.mark_read_multiple,
mark_all_read: notifications.mark_all_read,
prune: notifications.prune
};

@ -1,8 +1,9 @@
var RDB = require('./redis.js'), var RDB = require('./redis'),
posts = require('./posts.js'), posts = require('./posts'),
topics = require('./topics'), topics = require('./topics'),
threadTools = require('./threadTools.js'), threadTools = require('./threadTools'),
user = require('./user.js'), user = require('./user'),
websockets = require('./websockets'),
async = require('async'), async = require('async'),
nconf = require('nconf'), nconf = require('nconf'),
validator = require('validator'), validator = require('validator'),
@ -13,7 +14,7 @@ var RDB = require('./redis.js'),
postSearch = reds.createSearch('nodebbpostsearch'), postSearch = reds.createSearch('nodebbpostsearch'),
topicSearch = reds.createSearch('nodebbtopicsearch'), topicSearch = reds.createSearch('nodebbtopicsearch'),
winston = require('winston'), winston = require('winston'),
meta = require('./meta.js'), meta = require('./meta'),
Feed = require('./feed'); Feed = require('./feed');
(function(PostTools) { (function(PostTools) {
@ -107,7 +108,7 @@ var RDB = require('./redis.js'),
PostTools.parse(content, next); PostTools.parse(content, next);
} }
], function(err, results) { ], function(err, results) {
io.sockets.in('topic_' + results[0].tid).emit('event:post_edited', { websockets.in('topic_' + results[0].tid).emit('event:post_edited', {
pid: pid, pid: pid,
title: validator.sanitize(title).escape(), title: validator.sanitize(title).escape(),
isMainPost: results[0].isMainPost, isMainPost: results[0].isMainPost,

@ -170,15 +170,6 @@ var RDB = require('./redis.js'),
if(err) { if(err) {
return next(err); return next(err);
} }
var socketData = {
posts: [postData]
};
io.sockets.in('topic_' + tid).emit('event:new_post', socketData);
io.sockets.in('recent_posts').emit('event:new_post', socketData);
io.sockets.in('user/' + uid).emit('event:new_post', socketData);
next(); next();
}); });
} }
@ -187,7 +178,7 @@ var RDB = require('./redis.js'),
return callback(err, null); return callback(err, null);
} }
callback(null, 'Reply successful'); callback(null, postData);
}); });
}); });
} }
@ -485,19 +476,6 @@ var RDB = require('./redis.js'),
}); });
} }
Posts.getTopicPostStats = function() {
RDB.mget(['totaltopiccount', 'totalpostcount'], function(err, data) {
if (err === null) {
var stats = {
topics: data[0] ? data[0] : 0,
posts: data[1] ? data[1] : 0
};
io.sockets.emit('post.stats', stats);
} else
console.log(err);
});
}
Posts.reIndexPids = function(pids, callback) { Posts.reIndexPids = function(pids, callback) {

@ -9,7 +9,8 @@ var RDB = require('./redis.js'),
topicSearch = reds.createSearch('nodebbtopicsearch'), topicSearch = reds.createSearch('nodebbtopicsearch'),
winston = require('winston'), winston = require('winston'),
meta = require('./meta'), meta = require('./meta'),
nconf = require('nconf'); nconf = require('nconf'),
websockets = require('./websockets');
(function(ThreadTools) { (function(ThreadTools) {
@ -51,7 +52,7 @@ var RDB = require('./redis.js'),
topics.setTopicField(tid, 'locked', 1); topics.setTopicField(tid, 'locked', 1);
if (socket) { if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_locked', { websockets.in('topic_' + tid).emit('event:topic_locked', {
tid: tid, tid: tid,
status: 'ok' status: 'ok'
}); });
@ -69,7 +70,7 @@ var RDB = require('./redis.js'),
topics.setTopicField(tid, 'locked', 0); topics.setTopicField(tid, 'locked', 0);
if (socket) { if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_unlocked', { websockets.in('topic_' + tid).emit('event:topic_unlocked', {
tid: tid, tid: tid,
status: 'ok' status: 'ok'
}); });
@ -92,7 +93,7 @@ var RDB = require('./redis.js'),
topicSearch.remove(tid); topicSearch.remove(tid);
io.sockets.in('topic_' + tid).emit('event:topic_deleted', { websockets.in('topic_' + tid).emit('event:topic_deleted', {
tid: tid, tid: tid,
status: 'ok' status: 'ok'
}); });
@ -107,7 +108,7 @@ var RDB = require('./redis.js'),
RDB.incr('totaltopiccount'); RDB.incr('totaltopiccount');
ThreadTools.unlock(tid); ThreadTools.unlock(tid);
io.sockets.in('topic_' + tid).emit('event:topic_restored', { websockets.in('topic_' + tid).emit('event:topic_restored', {
tid: tid, tid: tid,
status: 'ok' status: 'ok'
}); });
@ -128,7 +129,7 @@ var RDB = require('./redis.js'),
}); });
if (socket) { if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_pinned', { websockets.in('topic_' + tid).emit('event:topic_pinned', {
tid: tid, tid: tid,
status: 'ok' status: 'ok'
}); });
@ -148,7 +149,7 @@ var RDB = require('./redis.js'),
RDB.zadd('categories:' + topicData.cid + ':tid', topicData.lastposttime, tid); RDB.zadd('categories:' + topicData.cid + ':tid', topicData.lastposttime, tid);
}); });
if (socket) { if (socket) {
io.sockets.in('topic_' + tid).emit('event:topic_unpinned', { websockets.in('topic_' + tid).emit('event:topic_unpinned', {
tid: tid, tid: tid,
status: 'ok' status: 'ok'
}); });
@ -196,7 +197,7 @@ var RDB = require('./redis.js'),
status: 'ok' status: 'ok'
}); });
io.sockets.in('topic_' + tid).emit('event:topic_moved', { websockets.in('topic_' + tid).emit('event:topic_moved', {
tid: tid tid: tid
}); });
} else { } else {

@ -675,11 +675,9 @@ var RDB = require('./redis.js'),
}); });
user.notifications.getUnreadByUniqueId(uid, 'topic:' + tid, function(err, nids) { user.notifications.getUnreadByUniqueId(uid, 'topic:' + tid, function(err, nids) {
if (nids.length > 0) { notifications.mark_read_multiple(nids, uid, function() {
async.each(nids, function(nid, next) {
notifications.mark_read(nid, uid, next); });
});
}
}); });
} }

@ -58,8 +58,6 @@ module.exports.isUserOnline = isUserOnline;
module.exports.init = function(io) { module.exports.init = function(io) {
global.io = io;
io.sockets.on('connection', function(socket) { io.sockets.on('connection', function(socket) {
var hs = socket.handshake, var hs = socket.handshake,
sessionID, uid, lastPostTime = 0; sessionID, uid, lastPostTime = 0;
@ -246,7 +244,7 @@ module.exports.init = function(io) {
}); });
socket.on('post.stats', function(data) { socket.on('post.stats', function(data) {
posts.getTopicPostStats(); emitTopicPostStats();
}); });
socket.on('user.email.exists', function(data) { socket.on('user.email.exists', function(data) {
@ -384,7 +382,7 @@ module.exports.init = function(io) {
posts: result.postData posts: result.postData
}); });
posts.getTopicPostStats(); emitTopicPostStats();
socket.emit('event:alert', { socket.emit('event:alert', {
title: 'Thank you for posting', title: 'Thank you for posting',
@ -423,7 +421,7 @@ module.exports.init = function(io) {
return; return;
} }
posts.reply(data.topic_id, uid, data.content, function(err, result) { posts.reply(data.topic_id, uid, data.content, function(err, postData) {
if(err) { if(err) {
if(err.message === 'content-too-short') { if(err.message === 'content-too-short') {
@ -441,9 +439,9 @@ module.exports.init = function(io) {
return; return;
} }
if (result) { if (postData) {
lastPostTime = Date.now(); lastPostTime = Date.now();
posts.getTopicPostStats(); emitTopicPostStats();
socket.emit('event:alert', { socket.emit('event:alert', {
title: 'Reply Successful', title: 'Reply Successful',
@ -451,6 +449,12 @@ module.exports.init = function(io) {
type: 'success', type: 'success',
timeout: 2000 timeout: 2000
}); });
var socketData = {
posts: [postData]
};
io.sockets.in('topic_' + postData.tid).emit('event:new_post', socketData);
io.sockets.in('recent_posts').emit('event:new_post', socketData);
io.sockets.in('user/' + postData.uid).emit('event:new_post', socketData);
} }
@ -495,7 +499,7 @@ module.exports.init = function(io) {
if (privileges.editable) { if (privileges.editable) {
threadTools.delete(data.tid, function(err) { threadTools.delete(data.tid, function(err) {
if (!err) { if (!err) {
posts.getTopicPostStats(); emitTopicPostStats();
socket.emit('api:topic.delete', { socket.emit('api:topic.delete', {
status: 'ok', status: 'ok',
tid: data.tid tid: data.tid
@ -510,7 +514,7 @@ module.exports.init = function(io) {
threadTools.privileges(data.tid, uid, function(privileges) { threadTools.privileges(data.tid, uid, function(privileges) {
if (privileges.editable) { if (privileges.editable) {
threadTools.restore(data.tid, socket, function(err) { threadTools.restore(data.tid, socket, function(err) {
posts.getTopicPostStats(); emitTopicPostStats();
socket.emit('api:topic.restore', { socket.emit('api:topic.restore', {
status: 'ok', status: 'ok',
@ -597,11 +601,12 @@ module.exports.init = function(io) {
socket.on('api:posts.delete', function(data, callback) { socket.on('api:posts.delete', function(data, callback) {
postTools.delete(uid, data.pid, function(err) { postTools.delete(uid, data.pid, function(err) {
if(err) { if(err) {
return callback(err); return callback(err);
} }
posts.getTopicPostStats(); emitTopicPostStats();
io.sockets.in('topic_' + data.tid).emit('event:post_deleted', { io.sockets.in('topic_' + data.tid).emit('event:post_deleted', {
pid: data.pid pid: data.pid
@ -616,7 +621,7 @@ module.exports.init = function(io) {
return callback(err); return callback(err);
} }
posts.getTopicPostStats(); emitTopicPostStats();
io.sockets.in('topic_' + data.tid).emit('event:post_restored', { io.sockets.in('topic_' + data.tid).emit('event:post_restored', {
pid: data.pid pid: data.pid
@ -636,9 +641,10 @@ module.exports.init = function(io) {
}); });
socket.on('api:notifications.mark_all_read', function(data, callback) { socket.on('api:notifications.mark_all_read', function(data, callback) {
console.log(notifications); notifications.mark_all_read(uid, function(err) {
require('./notifications').mark_all_read(uid, function(err) { if (!err) {
if (!err) callback(); callback();
}
}); });
}); });
@ -1011,6 +1017,22 @@ module.exports.init = function(io) {
socket.on('api:admin.theme.set', meta.themes.set); socket.on('api:admin.theme.set', meta.themes.set);
}); });
function emitTopicPostStats() {
RDB.mget(['totaltopiccount', 'totalpostcount'], function(err, data) {
if (err) {
return winston.err(err);
}
var stats = {
topics: data[0] ? data[0] : 0,
posts: data[1] ? data[1] : 0
};
io.sockets.emit('post.stats', stats);
});
}
module.exports.emitUserCount = function() { module.exports.emitUserCount = function() {
RDB.get('usercount', function(err, count) { RDB.get('usercount', function(err, count) {
io.sockets.emit('user.count', { io.sockets.emit('user.count', {

Loading…
Cancel
Save