try fixing both issues at the same time

master
Aevann 2024-11-15 15:02:46 +02:00
parent a5b991e495
commit f2b431aa1a
1 changed files with 19 additions and 14 deletions

View File

@ -36,6 +36,11 @@ typing = {}
cache.set('loggedin_chat', 0, timeout=86400) cache.set('loggedin_chat', 0, timeout=86400)
def get_request_referrer():
if '?m=' in request.referrer:
return request.referrer.split("?m=")[0]
return request.referrer
def auth_required_socketio(f): def auth_required_socketio(f):
def wrapper(*args, **kwargs): def wrapper(*args, **kwargs):
if not hasattr(g, 'db'): g.db = db_session() if not hasattr(g, 'db'): g.db = db_session()
@ -175,9 +180,9 @@ def speak(data, v):
if v.shadowbanned: if v.shadowbanned:
emit('speak', data) emit('speak', data)
else: else:
emit('speak', data, room=request.referrer) emit('speak', data, room=get_referrer())
typing[request.referrer] = [] typing[get_referrer()] = []
if membership and membership.is_mod: if membership and membership.is_mod:
added_users = [] added_users = []
@ -194,7 +199,7 @@ def speak(data, v):
g.db.flush() g.db.flush()
added_users.append((user.username, user.name_color, user.patron, user.id, bool(user.has_badge(303)))) added_users.append((user.username, user.name_color, user.patron, user.id, bool(user.has_badge(303))))
if added_users: if added_users:
emit("add", added_users, room=request.referrer) emit("add", added_users, room=get_referrer())
kicked_users = [] kicked_users = []
for i in chat_kicking_regex.finditer(text): for i in chat_kicking_regex.finditer(text):
@ -207,7 +212,7 @@ def speak(data, v):
send_notification(user.id, f"@{v.username} kicked you from their chat [{chat.name}](/chat/{chat.id})") send_notification(user.id, f"@{v.username} kicked you from their chat [{chat.name}](/chat/{chat.id})")
kicked_users.append(user.id) kicked_users.append(user.id)
if kicked_users: if kicked_users:
emit("kick", kicked_users, room=request.referrer) emit("kick", kicked_users, room=get_referrer())
if v.id == chat.owner_id: if v.id == chat.owner_id:
for i in chat_jannying_regex.finditer(text): for i in chat_jannying_regex.finditer(text):
@ -227,8 +232,8 @@ def speak(data, v):
send_notification(user.id, f"@{v.username} has removed you as a mod of their chat [{chat.name}](/chat/{chat.id})") send_notification(user.id, f"@{v.username} has removed you as a mod of their chat [{chat.name}](/chat/{chat.id})")
if chat.id != 1: if chat.id != 1:
print(request.referrer, flush=True) print(get_referrer(), flush=True)
alrdy_here = set(online[request.referrer].keys()) alrdy_here = set(online[get_referrer()].keys())
print(alrdy_here, flush=True) print(alrdy_here, flush=True)
memberships = g.db.query(ChatMembership).options(load_only(ChatMembership.user_id)).filter( memberships = g.db.query(ChatMembership).options(load_only(ChatMembership.user_id)).filter(
ChatMembership.chat_id == chat_id, ChatMembership.chat_id == chat_id,
@ -279,8 +284,8 @@ def refresh_online(room):
@socketio.on('connect') @socketio.on('connect')
@auth_required_socketio @auth_required_socketio
def connect(v): def connect(v):
if not request.referrer: stop(400, "Invalid referrer!") if not get_referrer(): stop(400, "Invalid referrer!")
room = request.referrer room = get_referrer()
if room.startswith(f'{SITE_FULL}/notifications/messages'): if room.startswith(f'{SITE_FULL}/notifications/messages'):
join_room(v.id) join_room(v.id)
@ -305,8 +310,8 @@ def connect(v):
@socketio.on('disconnect') @socketio.on('disconnect')
@auth_required_socketio @auth_required_socketio
def disconnect(v): def disconnect(v):
if not request.referrer: stop(400, "Invalid referrer!") if not get_referrer(): stop(400, "Invalid referrer!")
room = request.referrer room = get_referrer()
if room.startswith(f'{SITE_FULL}/notifications/messages'): if room.startswith(f'{SITE_FULL}/notifications/messages'):
leave_room(v.id) leave_room(v.id)
@ -329,8 +334,8 @@ def disconnect(v):
@socketio.on('heartbeat') @socketio.on('heartbeat')
@auth_required_socketio @auth_required_socketio
def heartbeat(v): def heartbeat(v):
if not request.referrer: stop(400, "Invalid referrer!") if not get_referrer(): stop(400, "Invalid referrer!")
room = request.referrer room = get_referrer()
if not online.get(room): if not online.get(room):
online[room] = {} online[room] = {}
@ -348,8 +353,8 @@ def heartbeat(v):
def typing_indicator(data, v): def typing_indicator(data, v):
if v.is_suspended or v.shadowbanned: return '' if v.is_suspended or v.shadowbanned: return ''
if not request.referrer: stop(400, "Invalid referrer!") if not get_referrer(): stop(400, "Invalid referrer!")
room = request.referrer room = get_referrer()
if not typing.get(room): if not typing.get(room):
typing[room] = [] typing[room] = []