Skip to content

Commit

Permalink
removed getUserSockets for chat
Browse files Browse the repository at this point in the history
emit to users rooms directly
  • Loading branch information
barisusakli committed Sep 3, 2014
1 parent 999da91 commit fdafb72
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Loader.init = function() {
silent: true
});

for(var x=0;x<numCPUs;x++) {
for(var x=0;x<4;x++) {
// Only the first worker sets up templates/sounds/jobs/etc
cluster.fork({ cluster_setup: x === 0 });
}
Expand Down
24 changes: 9 additions & 15 deletions src/socket.io/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,22 +204,18 @@ SocketModules.chats.send = function(socket, data, callback) {

// Recipient
SocketModules.chats.pushUnreadCount(touid);
server.getUserSockets(touid).forEach(function(s) {
s.emit('event:chats.receive', {
withUid: socket.uid,
message: message,
self: 0
});
server.in('uid_' + touid).emit('event:chats.receive', {
withUid: socket.uid,
message: message,
self: 0
});

// Sender
SocketModules.chats.pushUnreadCount(socket.uid);
server.getUserSockets(socket.uid).forEach(function(s) {
s.emit('event:chats.receive', {
withUid: touid,
message: message,
self: 1
});
server.in('uid_' + socket.uid).emit('event:chats.receive', {
withUid: touid,
message: message,
self: 1
});
});
};
Expand All @@ -246,9 +242,7 @@ SocketModules.chats.pushUnreadCount = function(uid) {
if (err) {
return;
}
server.getUserSockets(uid).forEach(function(s) {
s.emit('event:unread.updateChatCount', null, unreadCount);
});
server.in('uid_' + uid).emit('event:unread.updateChatCount', null, unreadCount);
});
};

Expand Down

0 comments on commit fdafb72

Please sign in to comment.