Revert "fix request referrer causing multiple separate rooms"

This reverts commit a633acfc6b.
master
Aevann 2024-11-15 14:56:42 +02:00
parent e2c534f4b5
commit 20d7c6b88f
1 changed files with 13 additions and 17 deletions

View File

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