From e2adf9e53d5496c8b23896f6391be372adc1f095 Mon Sep 17 00:00:00 2001 From: mummified-corroding-granny Date: Thu, 16 Feb 2023 13:41:58 +0000 Subject: [PATCH] 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: https://fsdfsd.net/rDrama/rDrama/pulls/121 Co-authored-by: mummified-corroding-granny Co-committed-by: mummified-corroding-granny --- files/routes/chat.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/files/routes/chat.py b/files/routes/chat.py index 860b09cbe..037362a9b 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -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,13 +146,19 @@ 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() if v.username in typing: typing.remove(v.username) - + return '', 204 @socketio.on('typing')