mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 11:05:54 +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 chatContent = chatModal.find('#chat-content'); | ||||||
|  |  | ||||||
| 		var date = new Date(parseInt(timestamp, 10)); | 		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); | 		scrollToBottom(chatContent); | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,11 +7,13 @@ | |||||||
| 				<h4>[[modules:chat.chatting_with]]</h4> | 				<h4>[[modules:chat.chatting_with]]</h4> | ||||||
| 			</div> | 			</div> | ||||||
| 			<div class="modal-body"> | 			<div class="modal-body"> | ||||||
| 				<textarea class="form-control" id="chat-content" cols="40" rows="10" readonly></textarea><br/> |                 <div id="chat-content" class="well well-sm" style="height:250px; overflow-y:scroll; font-size: 14px;"></div> | ||||||
| 				<input id="chat-message-input" type="text" class="form-control" name="chat-message" placeholder="[[modules:chat.placeholder]]"/> |                 <div class="input-group"> | ||||||
| 			</div> |                     <input id="chat-message-input" type="text" placeholder="[[modules:chat.placeholder]]" name="chat-message" class="form-control"> | ||||||
| 			<div class="modal-footer"> |                     <span class="input-group-btn"> | ||||||
| 				<button type="button" id="chat-message-send-btn" href="#" class="btn btn-primary btn-lg btn-block">[[modules:chat.send]]</button> |                         <button id="chat-message-send-btn" class="btn btn-primary" href="#" type="button">[[modules:chat.send]]</button> | ||||||
|  |                     </span> | ||||||
|  |                 </div> | ||||||
| 			</div> | 			</div> | ||||||
| 		</div> | 		</div> | ||||||
| 	</div> | 	</div> | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| var db = require('./database'), | var db = require('./database'), | ||||||
| 	async = require('async'), | 	async = require('async'), | ||||||
| 	user = require('./user'), | 	user = require('./user'), | ||||||
|  |     plugins = require('./plugins'); | ||||||
| 	meta = require('./meta'); | 	meta = require('./meta'); | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -62,14 +63,13 @@ var db = require('./database'), | |||||||
| 							return next(err); | 							return next(err); | ||||||
| 						} | 						} | ||||||
|  |  | ||||||
| 						if (message.fromuid === fromuid) { |                         Messaging.parse(message.content, message.fromuid, fromuid, tousername, function(result) { | ||||||
| 							message.content = 'You : ' + message.content; |                             message.content = result; | ||||||
| 						} else { |  | ||||||
| 							message.content = tousername + ' : ' + message.content; |  | ||||||
| 						} |  | ||||||
|  |  | ||||||
|                             messages.push(message); |                             messages.push(message); | ||||||
|                             next(null); |                             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) { | 	Messaging.updateChatTime = function(uid, toUid, callback) { | ||||||
| 		db.sortedSetAdd('uid:' + uid + ':chats', Date.now(), toUid, function(err) { | 		db.sortedSetAdd('uid:' + uid + ':chats', Date.now(), toUid, function(err) { | ||||||
| 			if (callback) { | 			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) { |             Messaging.addMessage(sessionData.uid, touid, msg, function(err, message) { | ||||||
|                 var numSockets = 0, |                 var numSockets = 0, | ||||||
|                     x; |                     x; | ||||||
| @@ -109,7 +109,8 @@ SocketModules.chats.send = function(data, sessionData) { | |||||||
|                         sessionData.userSockets[touid][x].emit('event:chats.receive', { |                         sessionData.userSockets[touid][x].emit('event:chats.receive', { | ||||||
|                             fromuid: sessionData.uid, |                             fromuid: sessionData.uid, | ||||||
|                             username: username, |                             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() |                             timestamp: Date.now() | ||||||
|                         }); |                         }); | ||||||
|                     } |                     } | ||||||
| @@ -123,13 +124,14 @@ SocketModules.chats.send = function(data, sessionData) { | |||||||
|                         sessionData.userSockets[sessionData.uid][x].emit('event:chats.receive', { |                         sessionData.userSockets[sessionData.uid][x].emit('event:chats.receive', { | ||||||
|                             fromuid: touid, |                             fromuid: touid, | ||||||
|                             username: toUsername, |                             username: toUsername, | ||||||
| 						message: 'You : ' + msg, |                             message: parsed, | ||||||
|                             timestamp: Date.now() |                             timestamp: Date.now() | ||||||
|                         }); |                         }); | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             }); |             }); | ||||||
|         }); |         }); | ||||||
|  | 	}); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| SocketModules.chats.list = function(callback, sessionData) { | SocketModules.chats.list = function(callback, sessionData) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user