mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 17:46:16 +01:00
Chat now supports markdown
This commit is contained in:
@@ -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 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 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>
|
||||
</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);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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,7 +97,7 @@ SocketModules.chats.send = function(data, sessionData) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Messaging.parse(msg, sessionData.uid, sessionData.uid, toUsername, function(parsed) {
|
||||
Messaging.addMessage(sessionData.uid, touid, msg, function(err, message) {
|
||||
var numSockets = 0,
|
||||
x;
|
||||
@@ -109,7 +109,8 @@ SocketModules.chats.send = function(data, sessionData) {
|
||||
sessionData.userSockets[touid][x].emit('event:chats.receive', {
|
||||
fromuid: sessionData.uid,
|
||||
username: username,
|
||||
message: finalMessage,
|
||||
// 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()
|
||||
});
|
||||
}
|
||||
@@ -123,13 +124,14 @@ SocketModules.chats.send = function(data, sessionData) {
|
||||
sessionData.userSockets[sessionData.uid][x].emit('event:chats.receive', {
|
||||
fromuid: touid,
|
||||
username: toUsername,
|
||||
message: 'You : ' + msg,
|
||||
message: parsed,
|
||||
timestamp: Date.now()
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
SocketModules.chats.list = function(callback, sessionData) {
|
||||
|
||||
Reference in New Issue
Block a user