|
|
|
@ -18,8 +18,8 @@ var posts = require('../posts'),
|
|
|
|
|
|
|
|
|
|
SocketModules.composer = {};
|
|
|
|
|
|
|
|
|
|
SocketModules.composer.push = function(data, callback, sessionData) {
|
|
|
|
|
if (parseInt(sessionData.uid, 10) > 0 || parseInt(meta.config.allowGuestPosting, 10) === 1) {
|
|
|
|
|
SocketModules.composer.push = function(socket, data, callback) {
|
|
|
|
|
if (parseInt(socket.uid, 10) > 0 || parseInt(meta.config.allowGuestPosting, 10) === 1) {
|
|
|
|
|
if (parseInt(data.pid, 10) > 0) {
|
|
|
|
|
|
|
|
|
|
async.parallel([
|
|
|
|
@ -46,7 +46,7 @@ SocketModules.composer.push = function(data, callback, sessionData) {
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketModules.composer.editCheck = function(pid, callback) {
|
|
|
|
|
SocketModules.composer.editCheck = function(socket, pid, callback) {
|
|
|
|
|
posts.getPostField(pid, 'tid', function(err, tid) {
|
|
|
|
|
postTools.isMain(pid, tid, function(err, isMain) {
|
|
|
|
|
callback({
|
|
|
|
@ -60,9 +60,9 @@ SocketModules.composer.editCheck = function(pid, callback) {
|
|
|
|
|
|
|
|
|
|
SocketModules.chats = {};
|
|
|
|
|
|
|
|
|
|
SocketModules.chats.get = function(data, callback, sessionData) {
|
|
|
|
|
SocketModules.chats.get = function(socket, data, callback) {
|
|
|
|
|
var touid = data.touid;
|
|
|
|
|
Messaging.getMessages(sessionData.uid, touid, function(err, messages) {
|
|
|
|
|
Messaging.getMessages(socket.uid, touid, function(err, messages) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return callback(null);
|
|
|
|
|
}
|
|
|
|
@ -71,16 +71,16 @@ SocketModules.chats.get = function(data, callback, sessionData) {
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketModules.chats.send = function(data, sessionData) {
|
|
|
|
|
SocketModules.chats.send = function(socket, data) {
|
|
|
|
|
|
|
|
|
|
var touid = data.touid;
|
|
|
|
|
if (touid === sessionData.uid || sessionData.uid === 0) {
|
|
|
|
|
if (touid === socket.uid || socket.uid === 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var msg = S(data.message).stripTags().s;
|
|
|
|
|
|
|
|
|
|
user.getMultipleUserFields([sessionData.uid, touid], ['username'], function(err, usersData) {
|
|
|
|
|
user.getMultipleUserFields([socket.uid, touid], ['username'], function(err, usersData) {
|
|
|
|
|
if(err) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -91,23 +91,23 @@ SocketModules.chats.send = function(data, sessionData) {
|
|
|
|
|
notifText = 'New message from <strong>' + username + '</strong>';
|
|
|
|
|
|
|
|
|
|
if (!module.parent.exports.isUserOnline(touid)) {
|
|
|
|
|
notifications.create(notifText, 'javascript:app.openChat('' + username + '', ' + sessionData.uid + ');', 'notification_' + sessionData.uid + '_' + touid, function(nid) {
|
|
|
|
|
notifications.create(notifText, 'javascript:app.openChat('' + username + '', ' + socket.uid + ');', 'notification_' + socket.uid + '_' + touid, function(nid) {
|
|
|
|
|
notifications.push(nid, [touid], function(success) {
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
Messaging.parse(msg, sessionData.uid, sessionData.uid, toUsername, function(parsed) {
|
|
|
|
|
Messaging.addMessage(sessionData.uid, touid, msg, function(err, message) {
|
|
|
|
|
Messaging.parse(msg, socket.uid, socket.uid, toUsername, function(parsed) {
|
|
|
|
|
Messaging.addMessage(socket.uid, touid, msg, function(err, message) {
|
|
|
|
|
var numSockets = 0,
|
|
|
|
|
x;
|
|
|
|
|
|
|
|
|
|
if (sessionData.userSockets[touid]) {
|
|
|
|
|
numSockets = sessionData.userSockets[touid].length;
|
|
|
|
|
if (socket.userSockets[touid]) {
|
|
|
|
|
numSockets = socket.userSockets[touid].length;
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < numSockets; ++x) {
|
|
|
|
|
sessionData.userSockets[touid][x].emit('event:chats.receive', {
|
|
|
|
|
fromuid: sessionData.uid,
|
|
|
|
|
socket.userSockets[touid][x].emit('event:chats.receive', {
|
|
|
|
|
fromuid: socket.uid,
|
|
|
|
|
username: username,
|
|
|
|
|
// todo this isnt very nice, but can't think of a better way atm
|
|
|
|
|
message: parsed.replace("chat-user-you'>You", "'>" + username),
|
|
|
|
@ -116,12 +116,12 @@ SocketModules.chats.send = function(data, sessionData) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sessionData.userSockets[sessionData.uid]) {
|
|
|
|
|
if (socket.userSockets[socket.uid]) {
|
|
|
|
|
|
|
|
|
|
numSockets = sessionData.userSockets[sessionData.uid].length;
|
|
|
|
|
numSockets = socket.userSockets[socket.uid].length;
|
|
|
|
|
|
|
|
|
|
for (x = 0; x < numSockets; ++x) {
|
|
|
|
|
sessionData.userSockets[sessionData.uid][x].emit('event:chats.receive', {
|
|
|
|
|
socket.userSockets[socket.uid][x].emit('event:chats.receive', {
|
|
|
|
|
fromuid: touid,
|
|
|
|
|
username: toUsername,
|
|
|
|
|
message: parsed,
|
|
|
|
@ -134,8 +134,8 @@ SocketModules.chats.send = function(data, sessionData) {
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketModules.chats.list = function(callback, sessionData) {
|
|
|
|
|
Messaging.getRecentChats(sessionData.uid, function(err, uids) {
|
|
|
|
|
SocketModules.chats.list = function(socket, data, callback) {
|
|
|
|
|
Messaging.getRecentChats(socket.uid, function(err, uids) {
|
|
|
|
|
if (err) {
|
|
|
|
|
winston.warn('[(socket) chats.list] Problem retrieving chats: ' + err.message);
|
|
|
|
|
}
|
|
|
|
@ -148,12 +148,12 @@ SocketModules.chats.list = function(callback, sessionData) {
|
|
|
|
|
|
|
|
|
|
SocketModules.notifications = {};
|
|
|
|
|
|
|
|
|
|
SocketModules.notifications.mark_read = function(nid, sessionData) {
|
|
|
|
|
notifications.mark_read(nid, sessionData.uid);
|
|
|
|
|
SocketModules.notifications.mark_read = function(socket, nid) {
|
|
|
|
|
notifications.mark_read(nid, socket.uid);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SocketModules.notifications.mark_all_read = function(data, callback, sessionData) {
|
|
|
|
|
notifications.mark_all_read(sessionData.uid, function(err) {
|
|
|
|
|
SocketModules.notifications.mark_all_read = function(socket, data, callback) {
|
|
|
|
|
notifications.mark_all_read(socket.uid, function(err) {
|
|
|
|
|
if (!err) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|