add chat users-online counter to chat icon on desktop header

remotes/1693045480750635534/spooky-22
Aevann1 2022-08-13 09:42:06 +02:00
parent 0c11a82e3c
commit 9557553508
3 changed files with 14 additions and 3 deletions

View File

@ -1,4 +1,4 @@
from files.__main__ import app
from files.__main__ import app, cache
from .get import *
from os import listdir, environ
from .const import *
@ -58,4 +58,4 @@ def inject_constants():
"LOTTERY_ENABLED": LOTTERY_ENABLED, "GUMROAD_LINK": GUMROAD_LINK,
"DEFAULT_THEME": DEFAULT_THEME, "DESCRIPTION": DESCRIPTION,
"has_sidebar": has_sidebar, "has_logo": has_logo, "has_app": has_app,
"FP": FP, "NOTIF_MODACTION_JL_MIN": NOTIF_MODACTION_JL_MIN}
"FP": FP, "NOTIF_MODACTION_JL_MIN": NOTIF_MODACTION_JL_MIN, "cache": cache, "ONLINE_STR": f'{SITE}_online'}

View File

@ -91,6 +91,9 @@ def connect(v):
if v.username not in online:
online.append(v.username)
emit("online", online, broadcast=True)
online = cache.get(f'{SITE}_online') or 0
online += 1
cache.set(f'{SITE}_online', online)
emit('typing', typing)
return '', 204
@ -101,6 +104,9 @@ def disconnect(v):
if v.username in online:
online.remove(v.username)
emit("online", online, broadcast=True)
online = cache.get(f'{SITE}_online') or 1
online -= 1
cache.set(f'{SITE}_online', online)
if v.username in typing: typing.remove(v.username)
emit('typing', typing, broadcast=True)

View File

@ -166,7 +166,12 @@
{% if FEATURES['CHAT'] -%}
<li class="nav-item d-flex align-items-center justify-content-center text-center mx-1">
<a class="nav-link" href="/chat/" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Chat"><i class="fas fa-messages"></i></a>
<a class="nav-link position-relative" href="/chat" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Chat">
<i class="fas fa-messages"></i>
<span class="notif-count bg-primary ml-1" style="padding-left: 4.5px;">
{{cache.get(ONLINE_STR) or 0}}
</span>
</a>
</li>
{%- endif %}