This commit is contained in:
Julian Lam
2015-07-24 14:25:23 -04:00
parent 87111ee6be
commit 474ff3ed35
5 changed files with 164 additions and 19 deletions

View File

@@ -4,7 +4,10 @@ var meta = require('../meta'),
Messaging = require('../messaging'),
utils = require('../../public/src/utils'),
async = require('async'),
server = require('./'),
rooms = require('./rooms'),
SocketModules = {
chats: {},
@@ -94,6 +97,37 @@ SocketModules.chats.getRecentChats = function(socket, data, callback) {
Messaging.getRecentChats(socket.uid, start, stop, callback);
};
SocketModules.chats.sync = function(socket, data, callback) {
var chats = [],
uids = [],
socketIds = rooms.clients('uid_' + socket.uid);
rooms.broadcast(socket, 'uid_' + socket.uid, 'query:chats.sync', {}, function(err, sessionData) {
sessionData.forEach(function(data) {
data.forEach(function(chat) {
if (uids.indexOf(chat.uid) === -1) {
chats.push(chat);
uids.push(chat.uid);
}
});
});
callback(err, chats);
});
};
SocketModules.chats.open = function(socket, data, callback) {
rooms.broadcast(socket, 'uid_' + socket.uid, 'event:chats.open', data);
};
SocketModules.chats.close = function(socket, data, callback) {
rooms.broadcast(socket, 'uid_' + socket.uid, 'event:chats.close', data);
};
SocketModules.chats.toggleNew = function(socket, data, callback) {
rooms.broadcast(socket, 'uid_' + socket.uid, 'event:chats.toggleNew', data);
};
/* Sounds */
SocketModules.sounds.getSounds = function(socket, data, callback) {