diff --git a/src/database/mongo.js b/src/database/mongo.js
index b8bd6f0a64..7a1b71c36d 100644
--- a/src/database/mongo.js
+++ b/src/database/mongo.js
@@ -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()
+ }
});
}
diff --git a/src/messaging.js b/src/messaging.js
index dce2ba6d0f..af3b8a1183 100644
--- a/src/messaging.js
+++ b/src/messaging.js
@@ -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 = "You: ";
+ var username,
+ picture;
+
+ if (parseInt(fromuid, 10) === parseInt(myuid, 10)) {
+ picture = '';
+ username = ' '+ myUserData.username + ': ';
} else {
- username = "" + tousername + ": ";
+ picture = '';
+ username = ' ' + toUserData.username + ': ';
}
- callback(username + parsed);
+ callback(picture + username + parsed);
});
};
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index b2bc6b0940..d59a18425b 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -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()
});
}