diff --git a/files/routes/chat.py b/files/routes/chat.py index ac392a59f..1140f044d 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -1,8 +1,6 @@ from files.helpers.const import SITE if SITE in ('pcmemes.net', 'localhost'): - count = 0 - import time from files.helpers.wrappers import auth_required from files.helpers.sanitize import sanitize @@ -14,6 +12,7 @@ if SITE in ('pcmemes.net', 'localhost'): socketio = SocketIO(app, async_mode='gevent') typing = [] + online = [] @app.get("/chat") @auth_required @@ -37,10 +36,11 @@ if SITE in ('pcmemes.net', 'localhost'): return '', 204 @socketio.on('connect') - def connect(): - global count - count += 1 - emit("count", count, broadcast=True) + @auth_required + def connect(v): + if v.username not in online: + online.append(v.username) + emit("online", online, broadcast=True) emit('typing', typing) return '', 204 @@ -48,9 +48,10 @@ if SITE in ('pcmemes.net', 'localhost'): @socketio.on('disconnect') @auth_required def disconnect(v): - global count - count -= 1 - emit("count", count, broadcast=True) + if v.username in online: + online.remove(v.username) + emit("online", online, broadcast=True) + if v.username in typing: typing.remove(v.username) emit('typing', typing, broadcast=True) return '', 204 diff --git a/files/templates/chat.html b/files/templates/chat.html index 6b2b146db..35cbff2ea 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -8,7 +8,7 @@ {% block content %}
- + 0 @@ -157,8 +157,12 @@ } }) - socket.on('count', function(data){ - document.getElementsByClassName('board-chat-count')[0].innerHTML = data + socket.on('online', function(data){ + document.getElementsByClassName('board-chat-count')[0].innerHTML = data.length + let online = '' + for (const u of data) + online += `
  • ${u}
  • ` + document.getElementById('online').innerHTML = online }) window.addEventListener('blur', function(){ diff --git a/files/templates/default.html b/files/templates/default.html index 9836461b8..64c7536ed 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -287,11 +287,14 @@ {% endblock %}
    - {% if home or sub and p %} - {% block sidebar %} + {% block sidebar %} + {% if home or sub and p %} {% include "sidebar_" + SITE_NAME + ".html" %} - {% endblock %} - {% endif %} + {% elif request.path == '/chat' %} + + {% endif %} + {% endblock %}