Chat now supports markdown

v1.18.x
MrWaffle 11 years ago
parent 1bf3d33765
commit b78dc3eca8

@ -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 = '<span style="color: darkgrey;" class="chat-timestamp">' + date.toLocaleTimeString() + '</span> ';
message = "<div>" + S(prefix + message).stripTags('p').s + "</div>";
chatContent.append('[' + date.toLocaleTimeString() + '] ' + message);
chatContent.append(message);
scrollToBottom(chatContent);
};

@ -7,11 +7,13 @@
<h4>[[modules:chat.chatting_with]]</h4>
</div>
<div class="modal-body">
<textarea class="form-control" id="chat-content" cols="40" rows="10" readonly></textarea><br/>
<input id="chat-message-input" type="text" class="form-control" name="chat-message" placeholder="[[modules:chat.placeholder]]"/>
</div>
<div class="modal-footer">
<button type="button" id="chat-message-send-btn" href="#" class="btn btn-primary btn-lg btn-block">[[modules:chat.send]]</button>
<div id="chat-content" class="well well-sm" style="height:250px; overflow-y:scroll; font-size: 14px;"></div>
<div class="input-group">
<input id="chat-message-input" type="text" placeholder="[[modules:chat.placeholder]]" name="chat-message" class="form-control">
<span class="input-group-btn">
<button id="chat-message-send-btn" class="btn btn-primary" href="#" type="button">[[modules:chat.send]]</button>
</span>
</div>
</div>
</div>
</div>

@ -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 = "<span class='chat-user chat-user-you'>You</span>: ";
} else {
username = "<span class='chat-user'>" + tousername + "</span>: ";
}
var result = username + parsed;
callback(result);
});
};
Messaging.updateChatTime = function(uid, toUid, callback) {
db.sortedSetAdd('uid:' + uid + ':chats', Date.now(), toUid, function(err) {
if (callback) {

@ -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()
});
}
}
});
});
});
};

Loading…
Cancel
Save