use shorter syntax in chat code

master
Aevann 2023-08-09 18:19:32 +03:00
parent 5fbe0c1440
commit c9abf14349
2 changed files with 37 additions and 37 deletions

View File

@ -69,12 +69,12 @@ socket.on('speak', function(json) {
let text_html
if (slurreplacer != '0') {
text = json['text_censored']
text_html = json['text_html_censored']
text = json.text_censored
text_html = json.text_html_censored
}
else {
text = json['text']
text_html = json['text_html']
text = json.text
text_html = json.text_html
}
chatline.classList.remove('chat-mention');
@ -91,42 +91,42 @@ socket.on('speak', function(json) {
const last_user = users[users.length-1].value;
const scrolled_down = (box.scrollHeight - box.scrollTop <= window.innerHeight)
if (last_user != json['user_id']) {
document.getElementsByClassName('avatar-pic')[0].src = '/pp/' + json["user_id"]
if (last_user != json.user_id) {
document.getElementsByClassName('avatar-pic')[0].src = '/pp/' + json.user_id
if (json['hat'])
document.getElementsByClassName('avatar-hat')[0].src = json['hat'] + "?h=7"
if (json.hat)
document.getElementsByClassName('avatar-hat')[0].src = json.hat + "?h=7"
else
document.getElementsByClassName('avatar-hat')[0].removeAttribute("src")
const userlink = document.getElementsByClassName('userlink')[0]
userlink.innerHTML = userlink.innerHTML.replace(userlink.textContent, json['username'])
userlink.href = '/@' + json['username']
userlink.style.color = '#' + json['namecolor']
userlink.innerHTML = userlink.innerHTML.replace(userlink.textContent, json.username)
userlink.href = '/@' + json.username
userlink.style.color = '#' + json.namecolor
document.getElementsByClassName('user_id')[0].value = json['user_id']
document.getElementsByClassName('user_id')[0].value = json.user_id
if (Date.now() - json['time']*1000 > 5000)
document.getElementsByClassName('time')[0].innerHTML = timeSince(json['time']*1000) + ' ago'
if (Date.now() - json.time*1000 > 5000)
document.getElementsByClassName('time')[0].innerHTML = timeSince(json.time*1000) + ' ago'
else
document.getElementsByClassName('time')[0].innerHTML = "just now"
}
document.getElementsByClassName('chat-line')[0].id = json['id']
document.getElementsByClassName('chat-line')[0].id = json.id
document.getElementsByClassName('text')[0].innerHTML = escapeHTML(text)
document.getElementsByClassName('chat-message')[0].innerHTML = text_html.replace(/data-src/g, 'src').replace(/data-cfsrc/g, 'src').replace(/style="display:none;visibility:hidden;"/g, '')
document.getElementsByClassName('quotes')[0].classList.add("d-none")
if (json['quotes']) {
const quoted = document.getElementById(json['quotes'])
if (json.quotes) {
const quoted = document.getElementById(json.quotes)
if (quoted) {
const quoted_user = quoted.parentElement.querySelector('.user_id').value
if (quoted_user == vid){
chatline.classList.add('chat-mention');
}
document.getElementsByClassName('quotes')[0].classList.remove("d-none")
document.getElementsByClassName('QuotedMessageLink')[0].href = '#' + json['quotes']
document.getElementsByClassName('QuotedMessageLink')[0].href = '#' + json.quotes
document.getElementsByClassName('QuotedUser')[0].innerHTML = quoted.parentElement.querySelector('.userlink').textContent
document.getElementsByClassName('QuotedMessage')[0].innerHTML = quoted.querySelector('.text').innerHTML
}
@ -135,7 +135,7 @@ socket.on('speak', function(json) {
let line = document.getElementsByClassName('chat-line')[0].cloneNode(true)
register_new_elements(line);
bs_trigger(line)
if (last_user == json['user_id']) {
if (last_user == json.user_id) {
box.querySelector('.chat-group:last-child').append(line)
}
else {
@ -144,11 +144,11 @@ socket.on('speak', function(json) {
box.append(chatgroup)
}
const line2 = document.getElementById(json['id'])
const line2 = document.getElementById(json.id)
register_new_elements(line2);
bs_trigger(line2)
if (scrolled_down || json['user_id'] == vid)
if (scrolled_down || json.user_id == vid)
box.scrollTo(0, box.scrollHeight)
})

View File

@ -231,31 +231,31 @@
{% macro chat_group_template(id, m) %}
<div class="chat-group">
<a class="font-weight-bold userlink" target="_blank" {% if m %}style="color:#{{m['namecolor']}}" href="/@{{m['username']}}" {% endif %}><div class="avatar profile-pic-20-wrapper mr-1"><img loading="lazy" class="avatar-pic pp20 mr-1" {% if m %}src="/pp/{{m['user_id']}}"{% endif %}><img class="avatar-hat profile-pic-20-hat hat" loading="lazy" {% if m %}src="{{m['hat']}}"{% endif %}></div>{% if m %}{{m['username']}}{% else %}NULL{% endif %}</a>
<span class="text-black time ml-1 mb-3 text-center">{% if m %}{{m['time'] | timestamp}}{% else %}just now{% endif %}</span>
<input hidden class="user_id" {% if m %}value="{{m['user_id']}}"{% endif %}>
<a class="font-weight-bold userlink" target="_blank" {% if m %}style="color:#{{m.namecolor}}" href="/@{{m.username}}" {% endif %}><div class="avatar profile-pic-20-wrapper mr-1"><img loading="lazy" class="avatar-pic pp20 mr-1" {% if m %}src="/pp/{{m.user_id}}"{% endif %}><img class="avatar-hat profile-pic-20-hat hat" loading="lazy" {% if m %}src="{{m.hat}}"{% endif %}></div>{% if m %}{{m.username}}{% else %}NULL{% endif %}</a>
<span class="text-black time ml-1 mb-3 text-center">{% if m %}{{m.time | timestamp}}{% else %}just now{% endif %}</span>
<input hidden class="user_id" {% if m %}value="{{m.user_id}}"{% endif %}>
{% endmacro %}
{% macro chat_line_template(id, m, vlink) %}
{% set quote_exists = m and m['quotes'] and messages.get(m['quotes']) %}
{% set mentioned = m and vlink in m['text_html'] or (quote_exists and messages[m['quotes']]['user_id'] == v.id) %}
{% set quote_exists = m and m.quotes and messages.get(m.quotes) %}
{% set mentioned = m and vlink in m.text_html or (quote_exists and messages[m.quotes].user_id == v.id) %}
<div class="chat-line {% if mentioned %}chat-mention{% endif %}" {% if m %}id="{{id}}"{% endif %}>
<div class="d-flex align-items-center">
<div class="text-muted chat-line-content">
<div class="{% if not (m and m['quotes']) %}d-none{% endif %} quotes" style="font-size:12px">
<a class="QuotedMessageLink" {% if m and m['quotes'] %}href="#{{m['quotes']}}"{% endif %}>
<div class="{% if not (m and m.quotes) %}d-none{% endif %} quotes" style="font-size:12px">
<a class="QuotedMessageLink" {% if m and m.quotes %}href="#{{m.quotes}}"{% endif %}>
<i class="fas fa-reply"></i>
<span class="text-primary">@<span class="QuotedUser">
{%- if quote_exists -%}
{{messages[m['quotes']]['username']}}
{{messages[m.quotes].username}}
{%- endif -%}
</span></span>:
<em class="QuotedMessage text-break">
{%- if quote_exists -%}
{%- if v.slurreplacer -%}
{{messages[m['quotes']]['text_censored']}}
{{messages[m.quotes].text_censored}}
{%- else -%}
{{messages[m['quotes']]['text']}}
{{messages[m.quotes].text}}
{%- endif -%}
{%- endif -%}
</em>
@ -266,23 +266,23 @@
<span class="chat-message text-black text-break">
{% if m %}
{% if v.slurreplacer %}
{{m['text_html_censored'] | safe}}
{{m.text_html_censored | safe}}
{% else %}
{{m['text_html'] | safe}}
{{m.text_html | safe}}
{% endif %}
{% endif %}
</span>
<span class="text d-none">
{%- if m -%}
{%- if v.slurreplacer -%}
{{m['text_censored']}}
{{m.text_censored}}
{%- else -%}
{{m['text']}}
{{m.text}}
{%- endif -%}
{%- endif -%}
</span>
<i class="quote btn fas fa-reply ml-auto" data-nonce="{{g.nonce}}" data-onclick="quote(this)"></i>
{% if v.admin_level >= PERMS['POST_COMMENT_MODERATION'] %}
{% if v.admin_level >= PERMS.POST_COMMENT_MODERATION %}
<i class="btn del delconfirm fas fa-trash-alt"></i>
<i class="btn d-none del delmsg fas fa-trash-alt text-danger" data-nonce="{{g.nonce}}" data-onclick="del(this)"></i>
{% endif %}
@ -297,7 +297,7 @@
<div id="chat-window" class="container p-0">
{% set messages_list = messages.items()|list %}
{% for id, m in messages_list %}
{% set same = loop.index > 1 and m['user_id'] == messages_list[loop.index-2][1]['user_id'] %}
{% set same = loop.index > 1 and m.user_id == messages_list[loop.index-2][1].user_id %}
{% if not same %}
{% if loop.index > 1 %}
</div>