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) {
if(err) {
winston.error('Error removing search ' + err.message);
}
if (typeof callback === 'function') {
callback()
}
});
}

@ -49,8 +49,7 @@ var db = require('./database'),
return callback(null, []);
}
user.getUserField(touid, 'username', function(err, tousername) {
user.getMultipleUserFields([fromuid, touid], ['username', 'picture'], function(err, userData) {
if(err) {
return callback(err, null);
}
@ -63,7 +62,7 @@ var db = require('./database'),
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;
messages.push(message);
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) {
if (err) {
return callback(message);
}
var username;
if (fromuid === myuid) {
username = "<span class='chat-user chat-user-you'>You</span>: ";
var username,
picture;
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 {
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;
user.getMultipleUserFields([socket.uid, touid], ['username'], function(err, usersData) {
user.getMultipleUserFields([socket.uid, touid], ['username', 'picture'], function(err, usersData) {
if(err) {
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) {
var numSockets = 0,
x;
@ -121,8 +121,7 @@ SocketModules.chats.send = function(socket, data) {
server.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),
message: parsed,
timestamp: Date.now()
});
}

Loading…
Cancel
Save