Lobby: online presence indicator

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HJhXuLD2Z6hv3Wqeq9UL9K
This commit is contained in:
Claude
2026-10-24 14:36:25 +00:00
parent 1db8a45cae
commit f6448aff85
4 changed files with 19 additions and 5 deletions
+8 -2
View File
@@ -659,19 +659,20 @@ def read_lobby(lid: str, user: dict = Depends(current_user)):
JOIN users u ON u.id = m.user_id LEFT JOIN characters c ON c.id = m.character_id
WHERE m.lobby_id=? ORDER BY m.joined""", (lid,)).fetchall()
members = []
online = hub.online(lid)
for r in rows:
mine = r["user_id"] == user["id"]
card = _card(r["data"], rules) if r["data"] else None
# The id is only given out where the viewer may open the full character (the DM sees all, a player only their own)
members.append({"username": r["username"], "me": mine, "character": card, "color": r["color"],
"mod": r["char_mod"] if (is_dm or mine) else None,
"mod": r["char_mod"] if (is_dm or mine) else None, "online": r["user_id"] in online,
"character_id": r["character_id"] if (is_dm or mine) and card else None})
hidden = bool(lobby["diff_hidden"])
diff = {"label": lobby["diff_label"], "mod": lobby["diff_mod"], "hidden": hidden}
if hidden and not is_dm:
diff = {"label": "", "mod": None, "hidden": True}
return {"id": lobby["id"], "name": lobby["name"], "dm": lobby["dm"], "is_dm": is_dm,
"code": lobby["code"] if is_dm else None, "members": members, "difficulty": diff,
"dm_online": lobby["owner_id"] in online, "code": lobby["code"] if is_dm else None, "members": members, "difficulty": diff,
"sounds": sounds_mod.settings(lobby["sounds"]), "levels": _levels(rules), "palette": [{"id": i, "hex": h} for i, h in PALETTE], "dm_color": DM_COLOR}
@@ -1153,9 +1154,12 @@ async def lobby_socket(websocket: WebSocket, lid: str):
await websocket.close(code=4401)
return
await websocket.accept()
was_online = user["id"] in hub.online(lid)
if not hub.add(lid, websocket, user["id"]):
await websocket.close(code=4429)
return
if not was_online:
hub.notify(lid, "lobby") # presence changed
try:
last_check = time.time()
while True:
@@ -1173,6 +1177,8 @@ async def lobby_socket(websocket: WebSocket, lid: str):
pass
finally:
hub.remove(lid, websocket)
if user["id"] not in hub.online(lid):
hub.notify(lid, "lobby")
try:
await websocket.close()
except Exception: