forked from rDrama/rDrama
add chat users-online counter to chat icon on desktop header
parent
0c11a82e3c
commit
9557553508
|
@ -1,4 +1,4 @@
|
||||||
from files.__main__ import app
|
from files.__main__ import app, cache
|
||||||
from .get import *
|
from .get import *
|
||||||
from os import listdir, environ
|
from os import listdir, environ
|
||||||
from .const import *
|
from .const import *
|
||||||
|
@ -58,4 +58,4 @@ def inject_constants():
|
||||||
"LOTTERY_ENABLED": LOTTERY_ENABLED, "GUMROAD_LINK": GUMROAD_LINK,
|
"LOTTERY_ENABLED": LOTTERY_ENABLED, "GUMROAD_LINK": GUMROAD_LINK,
|
||||||
"DEFAULT_THEME": DEFAULT_THEME, "DESCRIPTION": DESCRIPTION,
|
"DEFAULT_THEME": DEFAULT_THEME, "DESCRIPTION": DESCRIPTION,
|
||||||
"has_sidebar": has_sidebar, "has_logo": has_logo, "has_app": has_app,
|
"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'}
|
||||||
|
|
|
@ -91,6 +91,9 @@ def connect(v):
|
||||||
if v.username not in online:
|
if v.username not in online:
|
||||||
online.append(v.username)
|
online.append(v.username)
|
||||||
emit("online", online, broadcast=True)
|
emit("online", online, broadcast=True)
|
||||||
|
online = cache.get(f'{SITE}_online') or 0
|
||||||
|
online += 1
|
||||||
|
cache.set(f'{SITE}_online', online)
|
||||||
|
|
||||||
emit('typing', typing)
|
emit('typing', typing)
|
||||||
return '', 204
|
return '', 204
|
||||||
|
@ -101,6 +104,9 @@ def disconnect(v):
|
||||||
if v.username in online:
|
if v.username in online:
|
||||||
online.remove(v.username)
|
online.remove(v.username)
|
||||||
emit("online", online, broadcast=True)
|
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)
|
if v.username in typing: typing.remove(v.username)
|
||||||
emit('typing', typing, broadcast=True)
|
emit('typing', typing, broadcast=True)
|
||||||
|
|
|
@ -166,7 +166,12 @@
|
||||||
|
|
||||||
{% if FEATURES['CHAT'] -%}
|
{% if FEATURES['CHAT'] -%}
|
||||||
<li class="nav-item d-flex align-items-center justify-content-center text-center mx-1">
|
<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>
|
</li>
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue