Merge branch 'master' of github.com:designcreateplay/NodeBB

v1.18.x
Julian Lam 11 years ago
commit cef54fbf6d

@ -145,11 +145,14 @@
}); });
} }
module.searchRemove = function(key, id) { module.searchRemove = function(key, id, callback) {
db.collection('search').remove({id:id, key:key}, function(err, result) { db.collection('search').remove({id:id, key:key}, function(err, result) {
if(err) { if(err) {
winston.error('Error removing search ' + err.message); winston.error('Error removing search ' + err.message);
} }
if (typeof callback === 'function') {
callback()
}
}); });
} }

@ -49,8 +49,7 @@ var db = require('./database'),
return callback(null, []); return callback(null, []);
} }
user.getMultipleUserFields([fromuid, touid], ['username', 'picture'], function(err, userData) {
user.getUserField(touid, 'username', function(err, tousername) {
if(err) { if(err) {
return callback(err, null); return callback(err, null);
} }
@ -63,7 +62,7 @@ var db = require('./database'),
return next(err); return next(err);
} }
Messaging.parse(message.content, message.fromuid, fromuid, tousername, function(result) { Messaging.parse(message.content, message.fromuid, fromuid, userData[1], userData[0], function(result) {
message.content = result; message.content = result;
messages.push(message); messages.push(message);
next(null); next(null);
@ -82,19 +81,23 @@ var db = require('./database'),
}); });
}; };
Messaging.parse = function (message, fromuid, myuid, tousername, callback) { Messaging.parse = function (message, fromuid, myuid, toUserData, myUserData, callback) {
plugins.fireHook('filter:post.parse', message, function(err, parsed) { plugins.fireHook('filter:post.parse', message, function(err, parsed) {
if (err) { if (err) {
return callback(message); return callback(message);
} }
var username; var username,
if (fromuid === myuid) { picture;
username = "<span class='chat-user chat-user-you'>You</span>: ";
if (parseInt(fromuid, 10) === parseInt(myuid, 10)) {
picture = '<img class="chat-user-image" src="' + myUserData.picture + '">';
username = '<span class="chat-user chat-user-you"> '+ myUserData.username + '</span>: ';
} else { } else {
username = "<span class='chat-user'>" + tousername + "</span>: "; picture = '<img class="chat-user-image" src="' + toUserData.picture + '">';
username = '<span class="chat-user"> ' + toUserData.username + '</span>: ';
} }
callback(username + parsed); callback(picture + username + parsed);
}); });
}; };

@ -92,7 +92,7 @@ SocketModules.chats.send = function(socket, data) {
var msg = S(data.message).stripTags().s; var msg = S(data.message).stripTags().s;
user.getMultipleUserFields([socket.uid, touid], ['username'], function(err, usersData) { user.getMultipleUserFields([socket.uid, touid], ['username', 'picture'], function(err, usersData) {
if(err) { if(err) {
return; return;
} }
@ -109,7 +109,7 @@ SocketModules.chats.send = function(socket, data) {
}); });
}); });
} }
Messaging.parse(msg, socket.uid, socket.uid, toUsername, function(parsed) { Messaging.parse(msg, socket.uid, socket.uid, usersData[1], usersData[0], function(parsed) {
Messaging.addMessage(socket.uid, touid, msg, function(err, message) { Messaging.addMessage(socket.uid, touid, msg, function(err, message) {
var numSockets = 0, var numSockets = 0,
x; x;
@ -121,8 +121,7 @@ SocketModules.chats.send = function(socket, data) {
server.userSockets[touid][x].emit('event:chats.receive', { server.userSockets[touid][x].emit('event:chats.receive', {
fromuid: socket.uid, fromuid: socket.uid,
username: username, username: username,
// todo this isnt very nice, but can't think of a better way atm message: parsed,
message: parsed.replace("chat-user-you'>You", "'>" + username),
timestamp: Date.now() timestamp: Date.now()
}); });
} }

Loading…
Cancel
Save