more fixes

v1.18.x
barisusakli 9 years ago
parent 43c697a5df
commit c5d2f61b01

@ -311,7 +311,7 @@ var async = require('async'),
Messaging.notifyUser = function(fromuid, touid, messageObj) { Messaging.notifyUser = function(uid, roomId, messageObj) {
// Immediate notifications // Immediate notifications
// Recipient // Recipient
Messaging.pushUnreadCount(touid); Messaging.pushUnreadCount(touid);
@ -355,10 +355,10 @@ var async = require('async'),
async.waterfall([ async.waterfall([
function (next) { function (next) {
Messaging.roomExists(roomId, next); Messaging.isUserInRoom(uid, roomId, next);
}, },
function (roomExists, next) { function (inRoom, next) {
if (!roomExists) { if (!inRoom) {
return callback(null, false); return callback(null, false);
} }
user.getUserFields(uid, ['banned', 'email:confirmed'], next); user.getUserFields(uid, ['banned', 'email:confirmed'], next);

@ -10,7 +10,7 @@ var db = require('../database');
module.exports = function(Messaging) { module.exports = function(Messaging) {
Messaging.newMessage = function(fromuid, toUids, content, timestamp, callback) { Messaging.newMessage = function(uid, toUids, content, timestamp, callback) {
var roomId; var roomId;
async.waterfall([ async.waterfall([
function (next) { function (next) {
@ -21,30 +21,30 @@ module.exports = function(Messaging) {
}, },
function (_roomId, next) { function (_roomId, next) {
roomId = _roomId; roomId = _roomId;
db.sortedSetAdd('chat:room:' + roomId + ':uids', timestamp, fromuid, next); db.sortedSetAdd('chat:room:' + roomId + ':uids', timestamp, uid, next);
}, },
function (next) { function (next) {
Messaging.addUsersToRoom(fromuid, toUids, roomId, next); Messaging.addUsersToRoom(uid, toUids, roomId, next);
}, },
function (next) { function (next) {
Messaging.sendMessage(fromuid, roomId, content, timestamp, next); Messaging.sendMessage(uid, roomId, content, timestamp, next);
} }
], callback); ], callback);
}; };
Messaging.sendMessage = function(fromuid, roomId, content, timestamp, callback) { Messaging.sendMessage = function(uid, roomId, content, timestamp, callback) {
async.waterfall([ async.waterfall([
function (next) { function (next) {
Messaging.checkContent(content, next); Messaging.checkContent(content, next);
}, },
function (next) { function (next) {
Messaging.roomExists(roomId, next); Messaging.isUserInRoom(uid, roomId, next);
}, },
function (exists, next) { function (inRoom, next) {
if (!exists) { if (!inRoom) {
return next(new Error('[[error:chat-room-does-not-exist]]')); return next(new Error('[[error:not-allowed]]'));
} }
Messaging.addMessage(fromuid, roomId, content, timestamp, next); Messaging.addMessage(uid, roomId, content, timestamp, next);
} }
], callback); ], callback);
}; };
@ -74,8 +74,7 @@ module.exports = function(Messaging) {
message = { message = {
content: content, content: content,
timestamp: timestamp, timestamp: timestamp,
fromuid: fromuid, fromuid: fromuid
roomId: roomId
}; };
plugins.fireHook('filter:messaging.save', message, next); plugins.fireHook('filter:messaging.save', message, next);
@ -95,19 +94,19 @@ module.exports = function(Messaging) {
], next); ], next);
}, },
function (results, next) { function (results, next) {
Messaging.getMessagesData([mid], fromuid, touid, true, next); async.parallel({
messages: async.apply(Messaging.getMessagesData, [mid], fromuid, roomId, true),
isNewSet: async.apply(Messaging.isNewSet, fromuid, roomId, mid)
}, next);
}, },
function (messages, next) { function (results, next) {
Messaging.isNewSet(fromuid, touid, mid, next); if (!results.messages || !results.messages[0]) {
},
function (isNewSet, next) {
if (!messages || !messages[0]) {
return next(null, null); return next(null, null);
} }
messages[0].newSet = isNewSet; results.messages[0].newSet = results.isNewSet;
messages[0].mid = mid; results.messages[0].mid = mid;
next(null, messages[0]); next(null, results.messages[0]);
} }
], callback); ], callback);
}; };

@ -40,12 +40,11 @@ SocketModules.chats.getRaw = function(socket, data, callback) {
}; };
SocketModules.chats.send = function(socket, data, callback) { SocketModules.chats.send = function(socket, data, callback) {
if (!data) { if (!data || !data.roomId) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
var now = Date.now(), var now = Date.now();
touid = parseInt(data.touid, 10);
// Websocket rate limiting // Websocket rate limiting
socket.lastChatMessageTime = socket.lastChatMessageTime || 0; socket.lastChatMessageTime = socket.lastChatMessageTime || 0;
@ -55,17 +54,17 @@ SocketModules.chats.send = function(socket, data, callback) {
socket.lastChatMessageTime = now; socket.lastChatMessageTime = now;
} }
Messaging.canMessage(socket.uid, touid, function(err, allowed) { Messaging.canMessage(socket.uid, data.roomId, function(err, allowed) {
if (err || !allowed) { if (err || !allowed) {
return callback(err || new Error('[[error:chat-restricted]]')); return callback(err || new Error('[[error:chat-restricted]]'));
} }
Messaging.addMessage(socket.uid, touid, data.message, now, function(err, message) { Messaging.sendMessage(socket.uid, data.roomId, data.message, now, function(err, message) {
if (err) { if (err) {
return callback(err); return callback(err);
} }
Messaging.notifyUser(socket.uid, touid, message); Messaging.notifyUser(socket.uid, data.roomId, message);
callback(); callback();
}); });

Loading…
Cancel
Save