Chat: add minimalistic chat session tracking and fix shadow user spy problem (#121)
Kindly, Not sure if this is too dramaphobic. I also went with the just enough (TM) approach The issue this PR intends to fix: 1. user has no chat tabs open 2. user opens two chat tabs 3. user closes second chat tab 4. user disappears from sidebar and user count (because was removed from online py list) 5. user (became shadow user) can now spy on the chat without being listed Thanks, granny Reviewed-on: #121 Co-authored-by: mummified-corroding-granny <mummified-corroding-granny@noreply.fsdfsd.net> Co-committed-by: mummified-corroding-granny <mummified-corroding-granny@noreply.fsdfsd.net>pull/123/head
parent
0c670299c0
commit
e2adf9e53d
|
@ -3,6 +3,7 @@ import time
|
|||
import uuid
|
||||
|
||||
from flask_socketio import SocketIO, emit
|
||||
from flask import request
|
||||
|
||||
from files.helpers.actions import *
|
||||
from files.helpers.alerts import *
|
||||
|
@ -22,6 +23,7 @@ socketio = SocketIO(
|
|||
|
||||
typing = []
|
||||
online = []
|
||||
sessions = []
|
||||
cache.set(CHAT_ONLINE_CACHE_KEY, len(online), timeout=0)
|
||||
muted = cache.get(f'muted') or {}
|
||||
messages = cache.get(f'messages') or {}
|
||||
|
@ -132,6 +134,7 @@ def refresh_online():
|
|||
@admin_level_required(PERMS['CHAT'])
|
||||
def connect(v):
|
||||
|
||||
sessions.append([v.id, request.sid])
|
||||
if [v.username, v.id, v.name_color] not in online:
|
||||
online.append([v.username, v.id, v.name_color])
|
||||
|
||||
|
@ -143,6 +146,12 @@ def connect(v):
|
|||
@socketio.on('disconnect')
|
||||
@admin_level_required(PERMS['CHAT'])
|
||||
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:
|
||||
online.remove([v.username, v.id, v.name_color])
|
||||
refresh_online()
|
||||
|
|
Loading…
Reference in New Issue