feat(realtime): live online/offline events and unified search
Some checks failed
CI / test (push) Failing after 18s
Some checks failed
CI / test (push) Failing after 18s
- add websocket events user_online/user_offline - broadcast presence changes on first connect and final disconnect only - apply live presence updates in web chat store and realtime hook - move public discover into unified left search (users + groups/channels) - remove separate Discover Chats dialog/menu entry
This commit is contained in:
@@ -3,26 +3,30 @@ from redis.exceptions import RedisError
|
||||
from app.utils.redis_client import get_redis_client
|
||||
|
||||
|
||||
async def mark_user_online(user_id: int) -> None:
|
||||
async def mark_user_online(user_id: int) -> bool:
|
||||
try:
|
||||
redis = get_redis_client()
|
||||
key = f"presence:user:{user_id}"
|
||||
count = await redis.incr(key)
|
||||
if count == 1:
|
||||
await redis.expire(key, 3600)
|
||||
return True
|
||||
return False
|
||||
except RedisError:
|
||||
return
|
||||
return False
|
||||
|
||||
|
||||
async def mark_user_offline(user_id: int) -> None:
|
||||
async def mark_user_offline(user_id: int) -> bool:
|
||||
try:
|
||||
redis = get_redis_client()
|
||||
key = f"presence:user:{user_id}"
|
||||
value = await redis.decr(key)
|
||||
if value <= 0:
|
||||
await redis.delete(key)
|
||||
return True
|
||||
return False
|
||||
except RedisError:
|
||||
return
|
||||
return False
|
||||
|
||||
|
||||
async def is_user_online(user_id: int) -> bool:
|
||||
|
||||
Reference in New Issue
Block a user