Neda/Back/domains/realtime/presence_service.py

29 lines
626 B
Python

import uuid
from db.redis import (
add_presence,
remove_presence,
get_presence
)
async def user_join_group(group_id: str | uuid.UUID, user_id: str | uuid.UUID):
"""
Called when websocket connects
"""
await add_presence(str(group_id), str(user_id))
async def user_leave_group(group_id: str | uuid.UUID, user_id: str | uuid.UUID):
"""
Called when websocket disconnects
"""
await remove_presence(str(group_id), str(user_id))
async def list_online_users(group_id: str | uuid.UUID):
"""
Returns online users in a group
"""
return await get_presence(str(group_id))