closes #1825, closes #1674

This commit is contained in:
barisusakli
2014-07-19 10:33:27 -04:00
parent a69973e7a7
commit a4975cab33
6 changed files with 121 additions and 36 deletions

View File

@@ -189,6 +189,7 @@ SocketModules.chats.send = function(socket, data, callback) {
recipMessage.self = 0;
// Recipient
SocketModules.chats.pushUnreadCount(touid);
server.getUserSockets(touid).forEach(function(s) {
s.emit('event:chats.receive', {
withUid: socket.uid,
@@ -197,6 +198,7 @@ SocketModules.chats.send = function(socket, data, callback) {
});
// Sender
SocketModules.chats.pushUnreadCount(socket.uid);
server.getUserSockets(socket.uid).forEach(function(s) {
s.emit('event:chats.receive', {
withUid: touid,
@@ -221,6 +223,25 @@ function sendChatNotification(fromuid, touid, messageObj) {
}
}
SocketModules.chats.pushUnreadCount = function(uid) {
Messaging.getUnreadCount(uid, function(err, unreadCount) {
if (err) {
return;
}
server.getUserSockets(uid).forEach(function(s) {
s.emit('event:unread.updateChatCount', null, unreadCount);
});
});
};
SocketModules.chats.markRead = function(socket, touid, callback) {
Messaging.markRead(socket.uid, touid, function(err) {
if (!err) {
SocketModules.chats.pushUnreadCount(socket.uid);
}
});
};
SocketModules.chats.userStartTyping = function(socket, data, callback) {
sendTypingNotification('event:chats.userStartTyping', socket, data, callback);
};