add minimalistic chat session tracking
parent
0c2128811f
commit
a0f049335b
|
@ -3,6 +3,7 @@ import time
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from flask_socketio import SocketIO, emit
|
from flask_socketio import SocketIO, emit
|
||||||
|
from flask import request
|
||||||
|
|
||||||
from files.helpers.actions import *
|
from files.helpers.actions import *
|
||||||
from files.helpers.alerts import *
|
from files.helpers.alerts import *
|
||||||
|
@ -22,6 +23,7 @@ socketio = SocketIO(
|
||||||
|
|
||||||
typing = []
|
typing = []
|
||||||
online = []
|
online = []
|
||||||
|
sessions = []
|
||||||
cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0)
|
cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0)
|
||||||
muted = cache.get(f'muted') or {}
|
muted = cache.get(f'muted') or {}
|
||||||
messages = cache.get(f'messages') or {}
|
messages = cache.get(f'messages') or {}
|
||||||
|
@ -132,6 +134,7 @@ def refresh_online():
|
||||||
@admin_level_required(PERMS['CHAT'])
|
@admin_level_required(PERMS['CHAT'])
|
||||||
def connect(v):
|
def connect(v):
|
||||||
|
|
||||||
|
sessions.append([v.id, request.sid])
|
||||||
if [v.username, v.id, v.name_color] not in online:
|
if [v.username, v.id, v.name_color] not in online:
|
||||||
online.append([v.username, v.id, v.name_color])
|
online.append([v.username, v.id, v.name_color])
|
||||||
|
|
||||||
|
@ -143,13 +146,19 @@ def connect(v):
|
||||||
@socketio.on('disconnect')
|
@socketio.on('disconnect')
|
||||||
@admin_level_required(PERMS['CHAT'])
|
@admin_level_required(PERMS['CHAT'])
|
||||||
def disconnect(v):
|
def disconnect(v):
|
||||||
|
if ([v.id, request.sid]) in sessions:
|
||||||
|
sessions.remove([v.id, request.sid])
|
||||||
|
if any(v.id in i for i in sessions):
|
||||||
|
# user has other running sessions
|
||||||
|
return '', 204
|
||||||
|
|
||||||
if [v.username, v.id, v.name_color] in online:
|
if [v.username, v.id, v.name_color] in online:
|
||||||
online.remove([v.username, v.id, v.name_color])
|
online.remove([v.username, v.id, v.name_color])
|
||||||
refresh_online()
|
refresh_online()
|
||||||
|
|
||||||
if v.username in typing:
|
if v.username in typing:
|
||||||
typing.remove(v.username)
|
typing.remove(v.username)
|
||||||
|
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
@socketio.on('typing')
|
@socketio.on('typing')
|
||||||
|
|
Loading…
Reference in New Issue