mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 17:46:16 +01:00
chop chop
This commit is contained in:
@@ -232,8 +232,6 @@
|
|||||||
function(next) {
|
function(next) {
|
||||||
user.logIP(uid, req.ip);
|
user.logIP(uid, req.ip);
|
||||||
|
|
||||||
require('../socket.io').emitUserCount();
|
|
||||||
|
|
||||||
user.notifications.sendWelcomeNotification(uid);
|
user.notifications.sendWelcomeNotification(uid);
|
||||||
|
|
||||||
plugins.fireHook('filter:register.complete', {uid: uid, referrer: req.body.referrer}, next);
|
plugins.fireHook('filter:register.complete', {uid: uid, referrer: req.body.referrer}, next);
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ var SocketIO = require('socket.io'),
|
|||||||
user = require('../user'),
|
user = require('../user'),
|
||||||
topics = require('../topics'),
|
topics = require('../topics'),
|
||||||
logger = require('../logger'),
|
logger = require('../logger'),
|
||||||
meta = require('../meta'),
|
|
||||||
ratelimit = require('../middleware/ratelimit'),
|
ratelimit = require('../middleware/ratelimit'),
|
||||||
|
|
||||||
Sockets = {},
|
Sockets = {},
|
||||||
@@ -183,7 +182,6 @@ Sockets.init = function(server) {
|
|||||||
var socketCount = Sockets.getUserSocketCount(uid);
|
var socketCount = Sockets.getUserSocketCount(uid);
|
||||||
if (uid && socketCount <= 1) {
|
if (uid && socketCount <= 1) {
|
||||||
socket.broadcast.emit('event:user_status_change', {uid: uid, status: 'offline'});
|
socket.broadcast.emit('event:user_status_change', {uid: uid, status: 'offline'});
|
||||||
emitOnlineUserCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onUserDisconnect(uid, socket.id, socketCount);
|
onUserDisconnect(uid, socket.id, socketCount);
|
||||||
@@ -252,12 +250,6 @@ Sockets.logoutUser = function(uid) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Sockets.emitUserCount = function() {
|
|
||||||
user.count(function(err, count) {
|
|
||||||
io.sockets.emit('user.count', err ? {message:err.message} : null, count);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
Sockets.in = function(room) {
|
Sockets.in = function(room) {
|
||||||
return io.sockets.in(room);
|
return io.sockets.in(room);
|
||||||
};
|
};
|
||||||
@@ -344,9 +336,6 @@ Sockets.getUserRooms = function(uid) {
|
|||||||
return rooms;
|
return rooms;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/* Helpers */
|
|
||||||
|
|
||||||
Sockets.reqFromSocket = function(socket) {
|
Sockets.reqFromSocket = function(socket) {
|
||||||
var headers = socket.handshake.headers,
|
var headers = socket.handshake.headers,
|
||||||
host = headers.host,
|
host = headers.host,
|
||||||
@@ -363,25 +352,22 @@ Sockets.reqFromSocket = function(socket) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
Sockets.isUserOnline = isUserOnline;
|
Sockets.isUserOnline = function(uid) {
|
||||||
function isUserOnline(uid) {
|
|
||||||
if (!io) {
|
if (!io) {
|
||||||
// Special handling for install script (socket.io not initialised)
|
// Special handling for install script (socket.io not initialised)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array.isArray(io.sockets.manager.rooms['/uid_' + uid]);
|
return Array.isArray(io.sockets.manager.rooms['/uid_' + uid]);
|
||||||
}
|
};
|
||||||
|
|
||||||
Sockets.isUsersOnline = function(uids, callback) {
|
Sockets.isUsersOnline = function(uids, callback) {
|
||||||
var data = uids.map(isUserOnline);
|
var data = uids.map(Sockets.isUserOnline);
|
||||||
|
|
||||||
callback(null, data);
|
callback(null, data);
|
||||||
};
|
};
|
||||||
|
|
||||||
Sockets.updateRoomBrowsingText = updateRoomBrowsingText;
|
Sockets.updateRoomBrowsingText = function (roomName, selfUid) {
|
||||||
function updateRoomBrowsingText(roomName, selfUid) {
|
|
||||||
|
|
||||||
if (!roomName) {
|
if (!roomName) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -410,7 +396,7 @@ function updateRoomBrowsingText(roomName, selfUid) {
|
|||||||
total: Math.max(0, total - uids.length)
|
total: Math.max(0, total - uids.length)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
Sockets.getUidsInRoom = function(roomName) {
|
Sockets.getUidsInRoom = function(roomName) {
|
||||||
var uids = [];
|
var uids = [];
|
||||||
@@ -434,44 +420,6 @@ Sockets.getUidsInRoom = function(roomName) {
|
|||||||
return uids;
|
return uids;
|
||||||
};
|
};
|
||||||
|
|
||||||
Sockets.emitTopicPostStats = emitTopicPostStats;
|
|
||||||
function emitTopicPostStats(callback) {
|
|
||||||
db.getObjectFields('global', ['topicCount', 'postCount'], function(err, data) {
|
|
||||||
if (err) {
|
|
||||||
return winston.err(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
var stats = {
|
|
||||||
topics: data.topicCount ? data.topicCount : 0,
|
|
||||||
posts: data.postCount ? data.postCount : 0
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!callback) {
|
|
||||||
io.sockets.in('online_users').emit('meta.getUsageStats', null, stats);
|
|
||||||
} else {
|
|
||||||
callback(null, stats);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Sockets.emitOnlineUserCount = emitOnlineUserCount;
|
|
||||||
function emitOnlineUserCount(callback) {
|
|
||||||
var anon = Sockets.getOnlineAnonCount();
|
|
||||||
var registered = Sockets.getOnlineUserCount();
|
|
||||||
|
|
||||||
var returnObj = {
|
|
||||||
users: registered + anon,
|
|
||||||
anon: anon
|
|
||||||
};
|
|
||||||
|
|
||||||
if (callback) {
|
|
||||||
callback(null, returnObj);
|
|
||||||
} else {
|
|
||||||
io.sockets.in('online_users').emit('user.getActiveUsers', null, returnObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Exporting */
|
/* Exporting */
|
||||||
module.exports = Sockets;
|
module.exports = Sockets;
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var meta = require('../meta'),
|
var nconf = require('nconf'),
|
||||||
|
gravatar = require('gravatar'),
|
||||||
|
winston = require('winston'),
|
||||||
|
validator = require('validator'),
|
||||||
|
|
||||||
|
meta = require('../meta'),
|
||||||
user = require('../user'),
|
user = require('../user'),
|
||||||
topics = require('../topics'),
|
topics = require('../topics'),
|
||||||
logger = require('../logger'),
|
logger = require('../logger'),
|
||||||
plugins = require('../plugins'),
|
plugins = require('../plugins'),
|
||||||
emitter = require('../emitter'),
|
emitter = require('../emitter'),
|
||||||
|
|
||||||
nconf = require('nconf'),
|
|
||||||
gravatar = require('gravatar'),
|
|
||||||
winston = require('winston'),
|
|
||||||
validator = require('validator'),
|
|
||||||
websockets = require('./'),
|
websockets = require('./'),
|
||||||
|
|
||||||
SocketMeta = {
|
SocketMeta = {
|
||||||
@@ -56,10 +57,6 @@ SocketMeta.buildTitle = function(socket, text, callback) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketMeta.getUsageStats = function(socket, data, callback) {
|
|
||||||
module.parent.exports.emitTopicPostStats(callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Rooms */
|
/* Rooms */
|
||||||
|
|
||||||
SocketMeta.rooms.enter = function(socket, data, callback) {
|
SocketMeta.rooms.enter = function(socket, data, callback) {
|
||||||
|
|||||||
@@ -63,8 +63,6 @@ SocketPosts.reply = function(socket, data, callback) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
websockets.emitTopicPostStats();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -223,17 +221,15 @@ SocketPosts.restore = function(socket, data, callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function deleteOrRestore(command, socket, data, callback) {
|
function deleteOrRestore(command, socket, data, callback) {
|
||||||
if(!data) {
|
if (!data) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
postTools[command](socket.uid, data.pid, function(err, postData) {
|
postTools[command](socket.uid, data.pid, function(err, postData) {
|
||||||
if(err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
websockets.emitTopicPostStats();
|
|
||||||
|
|
||||||
var eventName = command === 'restore' ? 'event:post_restored' : 'event:post_deleted';
|
var eventName = command === 'restore' ? 'event:post_restored' : 'event:post_deleted';
|
||||||
websockets.server.sockets.in('topic_' + data.tid).emit(eventName, postData);
|
websockets.server.sockets.in('topic_' + data.tid).emit(eventName, postData);
|
||||||
|
|
||||||
@@ -250,8 +246,6 @@ SocketPosts.purge = function(socket, data, callback) {
|
|||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
websockets.emitTopicPostStats();
|
|
||||||
|
|
||||||
websockets.server.sockets.in('topic_' + data.tid).emit('event:post_purged', data.pid);
|
websockets.server.sockets.in('topic_' + data.tid).emit('event:post_purged', data.pid);
|
||||||
|
|
||||||
callback();
|
callback();
|
||||||
|
|||||||
@@ -59,8 +59,6 @@ SocketTopics.post = function(socket, data, callback) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
websockets.emitTopicPostStats();
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -210,7 +208,7 @@ SocketTopics.purge = function(socket, data, callback) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
websockets.emitTopicPostStats();
|
|
||||||
websockets.in('category_' + data.cid).emit('event:topic_purged', data.tids);
|
websockets.in('category_' + data.cid).emit('event:topic_purged', data.tids);
|
||||||
async.each(data.tids, function(tid, next) {
|
async.each(data.tids, function(tid, next) {
|
||||||
websockets.in('topic_' + tid).emit('event:topic_purged', tid);
|
websockets.in('topic_' + tid).emit('event:topic_purged', tid);
|
||||||
|
|||||||
@@ -31,10 +31,6 @@ SocketUser.deleteAccount = function(socket, data, callback) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketUser.count = function(socket, data, callback) {
|
|
||||||
user.count(callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketUser.emailExists = function(socket, data, callback) {
|
SocketUser.emailExists = function(socket, data, callback) {
|
||||||
if(data && data.email) {
|
if(data && data.email) {
|
||||||
user.email.exists(data.email, callback);
|
user.email.exists(data.email, callback);
|
||||||
@@ -326,10 +322,6 @@ SocketUser.getUnreadChatCount = function(socket, data, callback) {
|
|||||||
messaging.getUnreadCount(socket.uid, callback);
|
messaging.getUnreadCount(socket.uid, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketUser.getActiveUsers = function(socket, data, callback) {
|
|
||||||
module.parent.exports.emitOnlineUserCount(callback);
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketUser.loadMore = function(socket, data, callback) {
|
SocketUser.loadMore = function(socket, data, callback) {
|
||||||
if(!data || !data.set || parseInt(data.after, 10) < 0) {
|
if(!data || !data.set || parseInt(data.after, 10) < 0) {
|
||||||
return callback(new Error('[[error:invalid-data]]'));
|
return callback(new Error('[[error:invalid-data]]'));
|
||||||
|
|||||||
@@ -62,8 +62,6 @@ var winston = require('winston'),
|
|||||||
|
|
||||||
events[isDelete ? 'logTopicDelete' : 'logTopicRestore'](uid, tid);
|
events[isDelete ? 'logTopicDelete' : 'logTopicRestore'](uid, tid);
|
||||||
|
|
||||||
websockets.emitTopicPostStats();
|
|
||||||
|
|
||||||
emitTo('topic_' + tid);
|
emitTo('topic_' + tid);
|
||||||
emitTo('category_' + topicData.cid);
|
emitTo('category_' + topicData.cid);
|
||||||
|
|
||||||
|
|||||||
@@ -268,12 +268,6 @@ var async = require('async'),
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
User.count = function(callback) {
|
|
||||||
db.getObjectField('global', 'userCount', function(err, count) {
|
|
||||||
callback(err, count ? count : 0);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
User.getUidByUsername = function(username, callback) {
|
User.getUidByUsername = function(username, callback) {
|
||||||
db.getObjectField('username:uid', username, callback);
|
db.getObjectField('username:uid', username, callback);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user