mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-07-12 05:41:52 +02:00
optimizing browsing users
This commit is contained in:
@@ -162,16 +162,20 @@ Sockets.init = function(server) {
|
||||
|
||||
async.parallel({
|
||||
user: function(next) {
|
||||
user.getUserFields(uid, ['username', 'userslug'], next);
|
||||
user.getUserFields(uid, ['username', 'userslug', 'picture'], next);
|
||||
},
|
||||
isAdmin: function(next) {
|
||||
user.isAdministrator(uid, next);
|
||||
}
|
||||
}, function(err, userData) {
|
||||
if (err || !userData.user) {
|
||||
return;
|
||||
}
|
||||
socket.emit('event:connect', {
|
||||
status: 1,
|
||||
username: userData.user ? userData.user.username : 'guest',
|
||||
userslug: userData.user ? userData.user.userslug : '',
|
||||
username: userData.user.username,
|
||||
userslug: userData.user.userslug,
|
||||
picture: userData.user.picture,
|
||||
isAdmin: userData.isAdmin,
|
||||
uid: uid
|
||||
});
|
||||
@@ -208,7 +212,7 @@ Sockets.init = function(server) {
|
||||
|
||||
for(var roomName in io.sockets.manager.roomClients[socket.id]) {
|
||||
if (roomName.indexOf('topic') !== -1) {
|
||||
updateRoomBrowsingText(roomName.slice(1));
|
||||
io.sockets.in(roomName.slice(1)).emit('event:user_leave', socket.uid);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -368,15 +372,17 @@ Sockets.isUsersOnline = function(uids, callback) {
|
||||
};
|
||||
|
||||
Sockets.updateRoomBrowsingText = updateRoomBrowsingText;
|
||||
function updateRoomBrowsingText(roomName) {
|
||||
function updateRoomBrowsingText(roomName, selfUid) {
|
||||
|
||||
if (!roomName) {
|
||||
return;
|
||||
}
|
||||
|
||||
var uids = Sockets.getUidsInRoom(roomName),
|
||||
anonymousCount = Sockets.getAnonCountInRoom(roomName);
|
||||
|
||||
var uids = Sockets.getUidsInRoom(roomName);
|
||||
uids = uids.slice(0, 9);
|
||||
if (selfUid) {
|
||||
uids = [selfUid].concat(uids);
|
||||
}
|
||||
user.getMultipleUserFields(uids, ['uid', 'username', 'userslug', 'picture', 'status'], function(err, users) {
|
||||
if(!err) {
|
||||
users = users.filter(function(user) {
|
||||
@@ -385,7 +391,6 @@ function updateRoomBrowsingText(roomName) {
|
||||
|
||||
io.sockets.in(roomName).emit('event:update_users_in_room', {
|
||||
users: users,
|
||||
anonymousCount: anonymousCount,
|
||||
room: roomName
|
||||
});
|
||||
}
|
||||
|
||||
@@ -62,24 +62,23 @@ SocketMeta.getUsageStats = function(socket, data, callback) {
|
||||
/* Rooms */
|
||||
|
||||
SocketMeta.rooms.enter = function(socket, data, callback) {
|
||||
if(!data) {
|
||||
if (!data) {
|
||||
return callback(new Error('[[error:invalid-data]]'));
|
||||
}
|
||||
|
||||
if (data.leave) {
|
||||
socket.leave(data.leave);
|
||||
if (socket.uid && data.leave.indexOf('topic') !== -1) {
|
||||
websockets.in(data.leave).emit('event:user_leave', socket.uid);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.enter) {
|
||||
socket.join(data.enter);
|
||||
}
|
||||
|
||||
if (data.leave && data.leave !== data.enter && data.leave.indexOf('topic') !== -1) {
|
||||
module.parent.exports.updateRoomBrowsingText(data.leave);
|
||||
}
|
||||
|
||||
if (data.enter.indexOf('topic') !== -1) {
|
||||
module.parent.exports.updateRoomBrowsingText(data.enter);
|
||||
if (socket.uid && data.enter.indexOf('topic') !== -1) {
|
||||
data.uid = socket.uid;
|
||||
websockets.in(data.enter).emit('event:user_enter', data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -64,6 +64,7 @@ SocketTopics.enter = function(socket, tid, callback) {
|
||||
SocketTopics.markAsRead(socket, tid);
|
||||
topics.markTopicNotificationsRead(tid, socket.uid);
|
||||
topics.increaseViewCount(tid);
|
||||
websockets.updateRoomBrowsingText('topic_' + tid);
|
||||
};
|
||||
|
||||
SocketTopics.postcount = function(socket, tid, callback) {
|
||||
|
||||
Reference in New Issue
Block a user