Add ratism to chatbox
This commit is contained in:
parent
ca89510799
commit
acec52f71b
2 changed files with 15 additions and 10 deletions
|
@ -14,10 +14,11 @@ import json
|
||||||
def format_messages(messages):
|
def format_messages(messages):
|
||||||
msg_list = [{
|
msg_list = [{
|
||||||
'time': msg.time,
|
'time': msg.time,
|
||||||
'author': str(msg.author),
|
'author': msg.author,
|
||||||
'body': msg.body,
|
'body': msg.body,
|
||||||
'image': gravatar(msg.author, 32),
|
'image': gravatar(msg.author, 32),
|
||||||
'id': msg.id
|
'id': msg.id,
|
||||||
|
'css_class': msg.author.css_class,
|
||||||
} for msg in messages]
|
} for msg in messages]
|
||||||
return json.dumps(msg_list, default=str)
|
return json.dumps(msg_list, default=str)
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
data['time'],
|
data['time'],
|
||||||
data['id'],
|
data['id'],
|
||||||
data['image'],
|
data['image'],
|
||||||
|
data['css_class'],
|
||||||
true);
|
true);
|
||||||
// console.log(data);
|
// console.log(data);
|
||||||
$('#chat-box').scrollTop($('#chat-box')[0].scrollHeight);
|
$('#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)
|
// if (isNew) content = encodeHTML(content)
|
||||||
time = new Date(time);
|
time = new Date(time);
|
||||||
time = moment(time).format("HH:mm DD-MM-YYYY");
|
time = moment(time).format("HH:mm DD-MM-YYYY");
|
||||||
content = encodeHTML(content);
|
content = encodeHTML(content);
|
||||||
li = `<li class="message">
|
li = `<li class="message">
|
||||||
<img src="${image}" class="profile-pic">
|
<img src="${image}" class="profile-pic">
|
||||||
<div class="body-message">
|
<div class="body-message">
|
||||||
<div class="user-time">
|
<div class="user-time">
|
||||||
<a href="{{ url('user_page') }}/${user}" class="user">
|
<span class="${css_class}">
|
||||||
${user}
|
<a href="{{ url('user_page') }}/${user}" class="user">
|
||||||
</a>
|
${user}
|
||||||
|
</a>
|
||||||
|
</span>
|
||||||
<span class="time">${time}</span>
|
<span class="time">${time}</span>
|
||||||
{% if request.user.is_staff %}
|
{% if request.user.is_staff %}
|
||||||
<a class="chatbtn_remove_mess" style="color:red; cursor: pointer;" data-messtime="${time}" data-author="${user}" data-messid="${messid}">Delete</a>
|
<a class="chatbtn_remove_mess" style="color:red; cursor: pointer;" data-messtime="${time}" data-author="${user}" data-messid="${messid}">Delete</a>
|
||||||
|
@ -68,7 +71,7 @@
|
||||||
ul = $('#chat-log')
|
ul = $('#chat-log')
|
||||||
{% autoescape on %}
|
{% autoescape on %}
|
||||||
{% for msg in message %}
|
{% for msg in message %}
|
||||||
loadMessage("{{msg.body|safe|escapejs}}", `{{msg.author}}`, `{{msg.time}}`, `{{msg.id}}`, `{{gravatar(msg.author, 32)}}`);
|
loadMessage("{{msg.body|safe|escapejs}}", `{{msg.author}}`, `{{msg.time}}`, `{{msg.id}}`, `{{gravatar(msg.author, 32)}}`,`{{msg.author.css_class}}`);
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endautoescape %}
|
{% endautoescape %}
|
||||||
$('#chat-box').scrollTop($('#chat-box')[0].scrollHeight);
|
$('#chat-box').scrollTop($('#chat-box')[0].scrollHeight);
|
||||||
|
@ -93,7 +96,7 @@
|
||||||
data = JSON.parse(data)
|
data = JSON.parse(data)
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
for (msg of data) {
|
for (msg of data) {
|
||||||
loadMessage(msg.body, msg.author, msg.time, msg.id, msg.image)
|
loadMessage(msg.body, msg.author, msg.time, msg.id, msg.image, msg.css_class)
|
||||||
}
|
}
|
||||||
|
|
||||||
loader.hide()
|
loader.hide()
|
||||||
|
@ -137,6 +140,7 @@
|
||||||
'image': img,
|
'image': img,
|
||||||
'author': '{{request.profile}}',
|
'author': '{{request.profile}}',
|
||||||
'author_id': {{request.profile.id}},
|
'author_id': {{request.profile.id}},
|
||||||
|
'css_class': '{{request.profile.css_class}}',
|
||||||
}
|
}
|
||||||
|
|
||||||
chatSocket.send(JSON.stringify({
|
chatSocket.send(JSON.stringify({
|
||||||
|
|
Loading…
Add table
Reference in a new issue