@@ -337,28 +337,6 @@ async def remove_connection(redis_client: aioredis.Redis, pad_id: UUID, user_id:
337337 except Exception as e :
338338 print (f"Error removing connection from Redis: { e } " )
339339
340- async def get_connected_users (redis_client : aioredis .Redis , pad_id : UUID ) -> List [Dict [str , str ]]:
341- """Get all connected users from the pad users hash as a list of dicts with user_id and username."""
342- key = f"pad:users:{ pad_id } "
343- try :
344- # Get all users from the hash
345- all_users = await redis_client .hgetall (key )
346-
347- # Convert to list of dicts with user_id and username
348- connected_users = []
349- for user_id , user_data_str in all_users .items ():
350- user_id_str = user_id .decode () if isinstance (user_id , bytes ) else user_id
351- user_data = json .loads (user_data_str .decode () if isinstance (user_data_str , bytes ) else user_data_str )
352- connected_users .append ({
353- "user_id" : user_id_str ,
354- "username" : user_data ["username" ]
355- })
356-
357- return connected_users
358- except Exception as e :
359- print (f"Error getting connected users from Redis: { e } " )
360- return []
361-
362340@ws_router .websocket ("/ws/pad/{pad_id}" )
363341async def websocket_endpoint (
364342 websocket : WebSocket ,
@@ -391,9 +369,9 @@ async def websocket_endpoint(
391369 redis_client = await RedisClient .get_instance ()
392370
393371 await add_connection (redis_client , pad_id , str (user .id ), user .username , connection_id )
394- connected_users = await get_connected_users (redis_client , pad_id )
395372
396373 # Send connected message to client with connected users info
374+ connected_users = await pad .get_connected_users ()
397375 connected_msg = WebSocketMessage (
398376 type = "connected" ,
399377 pad_id = str (pad_id ),
0 commit comments