diff --git a/public/src/modules/chat.js b/public/src/modules/chat.js
index af5c4cc02c..c35f138829 100644
--- a/public/src/modules/chat.js
+++ b/public/src/modules/chat.js
@@ -227,8 +227,11 @@ define(['taskbar', 'string'], function(taskbar, S) {
var chatContent = chatModal.find('#chat-content');
var date = new Date(parseInt(timestamp, 10));
+ // todo Add this to a stylesheet instead of style tag
+ var prefix = '' + date.toLocaleTimeString() + ' ';
+ message = "
" + S(prefix + message).stripTags('p').s + "
";
- chatContent.append('[' + date.toLocaleTimeString() + '] ' + message);
+ chatContent.append(message);
scrollToBottom(chatContent);
};
diff --git a/public/templates/chat.tpl b/public/templates/chat.tpl
index c71df40147..612bbcd018 100644
--- a/public/templates/chat.tpl
+++ b/public/templates/chat.tpl
@@ -7,11 +7,13 @@
[[modules:chat.chatting_with]]
-
-
-
-
diff --git a/src/messaging.js b/src/messaging.js
index ec0c62512e..8ef3954f20 100644
--- a/src/messaging.js
+++ b/src/messaging.js
@@ -1,6 +1,7 @@
var db = require('./database'),
async = require('async'),
user = require('./user'),
+ plugins = require('./plugins');
meta = require('./meta');
@@ -62,14 +63,13 @@ var db = require('./database'),
return next(err);
}
- if (message.fromuid === fromuid) {
- message.content = 'You : ' + message.content;
- } else {
- message.content = tousername + ' : ' + message.content;
- }
+ Messaging.parse(message.content, message.fromuid, fromuid, tousername, function(result) {
+ message.content = result;
+ messages.push(message);
+ next(null);
+ });
+
- messages.push(message);
- next(null);
});
}
@@ -84,6 +84,22 @@ var db = require('./database'),
});
};
+ Messaging.parse = function (message, fromuid, myuid, tousername, callback) {
+ plugins.fireHook('filter:post.parse', message, function(err, parsed) {
+ if (err) {
+ return callback(message);
+ }
+ var username;
+ if (fromuid === myuid) {
+ username = "You : ";
+ } else {
+ username = "" + tousername + " : ";
+ }
+ var result = username + parsed;
+ callback(result);
+ });
+ };
+
Messaging.updateChatTime = function(uid, toUid, callback) {
db.sortedSetAdd('uid:' + uid + ':chats', Date.now(), toUid, function(err) {
if (callback) {
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index aa43c03b0d..a85a38bb2d 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -97,38 +97,40 @@ SocketModules.chats.send = function(data, sessionData) {
});
});
}
-
- Messaging.addMessage(sessionData.uid, touid, msg, function(err, message) {
- var numSockets = 0,
- x;
-
- if (sessionData.userSockets[touid]) {
- numSockets = sessionData.userSockets[touid].length;
-
- for (x = 0; x < numSockets; ++x) {
- sessionData.userSockets[touid][x].emit('event:chats.receive', {
- fromuid: sessionData.uid,
- username: username,
- message: finalMessage,
- timestamp: Date.now()
- });
- }
- }
-
- if (sessionData.userSockets[sessionData.uid]) {
-
- numSockets = sessionData.userSockets[sessionData.uid].length;
-
- for (x = 0; x < numSockets; ++x) {
- sessionData.userSockets[sessionData.uid][x].emit('event:chats.receive', {
- fromuid: touid,
- username: toUsername,
- message: 'You : ' + msg,
- timestamp: Date.now()
- });
- }
- }
- });
+ Messaging.parse(msg, sessionData.uid, sessionData.uid, toUsername, function(parsed) {
+ Messaging.addMessage(sessionData.uid, touid, msg, function(err, message) {
+ var numSockets = 0,
+ x;
+
+ if (sessionData.userSockets[touid]) {
+ numSockets = sessionData.userSockets[touid].length;
+
+ for (x = 0; x < numSockets; ++x) {
+ sessionData.userSockets[touid][x].emit('event:chats.receive', {
+ fromuid: sessionData.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),
+ timestamp: Date.now()
+ });
+ }
+ }
+
+ if (sessionData.userSockets[sessionData.uid]) {
+
+ numSockets = sessionData.userSockets[sessionData.uid].length;
+
+ for (x = 0; x < numSockets; ++x) {
+ sessionData.userSockets[sessionData.uid][x].emit('event:chats.receive', {
+ fromuid: touid,
+ username: toUsername,
+ message: parsed,
+ timestamp: Date.now()
+ });
+ }
+ }
+ });
+ });
});
};