diff --git a/chat_box/views.py b/chat_box/views.py index d5bc8a0..91604d7 100644 --- a/chat_box/views.py +++ b/chat_box/views.py @@ -14,10 +14,11 @@ import json def format_messages(messages): msg_list = [{ 'time': msg.time, - 'author': str(msg.author), + 'author': msg.author, 'body': msg.body, 'image': gravatar(msg.author, 32), - 'id': msg.id + 'id': msg.id, + 'css_class': msg.author.css_class, } for msg in messages] return json.dumps(msg_list, default=str) diff --git a/templates/chat/chat.html b/templates/chat/chat.html index 1c8e499..960190c 100644 --- a/templates/chat/chat.html +++ b/templates/chat/chat.html @@ -22,6 +22,7 @@ data['time'], data['id'], data['image'], + data['css_class'], true); // console.log(data); $('#chat-box').scrollTop($('#chat-box')[0].scrollHeight); @@ -33,18 +34,20 @@ }); } - function loadMessage(content, user, time, messid, image, isNew) { + function loadMessage(content, user, time, messid, image, css_class, isNew) { // if (isNew) content = encodeHTML(content) - time = new Date(time); - time = moment(time).format("HH:mm DD-MM-YYYY"); + time = new Date(time); + time = moment(time).format("HH:mm DD-MM-YYYY"); content = encodeHTML(content); li = `