JCEF migration: add jcefmaven dep, make JavaFX optional, create LogBridge, wire JCEFLauncher entry point
This commit is contained in:
@@ -116,7 +116,12 @@ async def remove_friend(
|
||||
@router.get("/friends/list")
|
||||
async def list_friends(current_user: dict = Depends(get_current_user)):
|
||||
friends = []
|
||||
stale_cutoff = time.time() - 300
|
||||
with get_db() as conn:
|
||||
# Auto-clean stale online
|
||||
conn.execute("UPDATE user_status SET is_online = 0 WHERE last_seen < ?", (stale_cutoff,))
|
||||
conn.commit()
|
||||
|
||||
rows = conn.execute("""
|
||||
SELECT u.id, u.username, u.role,
|
||||
COALESCE(us.is_online, 0) as online,
|
||||
@@ -159,6 +164,17 @@ async def list_friend_requests(current_user: dict = Depends(get_current_user)):
|
||||
})
|
||||
return {"requests": requests}
|
||||
|
||||
def get_friends_ids(user_id: int) -> list[int]:
|
||||
"""Get list of friend user_ids for a given user"""
|
||||
with get_db() as conn:
|
||||
rows = conn.execute("""
|
||||
SELECT CASE WHEN f.requester_id = ? THEN f.target_id ELSE f.requester_id END as friend_id
|
||||
FROM friendships f
|
||||
WHERE (f.requester_id = ? OR f.target_id = ?) AND f.status = 'accepted'
|
||||
""", (user_id, user_id, user_id)).fetchall()
|
||||
return [r["friend_id"] for r in rows]
|
||||
|
||||
|
||||
@router.post("/friends/status")
|
||||
async def update_status(
|
||||
req: StatusUpdateRequest,
|
||||
@@ -173,4 +189,11 @@ async def update_status(
|
||||
current_pack = COALESCE(excluded.current_pack, user_status.current_pack),
|
||||
last_seen = CURRENT_TIMESTAMP
|
||||
""", (current_user["id"], int(req.online), req.current_pack or ""))
|
||||
# Broadcast status change to friends via WebSocket
|
||||
try:
|
||||
from ws_manager import manager
|
||||
friend_ids = get_friends_ids(current_user["id"])
|
||||
await manager.broadcast_status_change(current_user["id"], friend_ids)
|
||||
except Exception:
|
||||
pass
|
||||
return {"status": "ok"}
|
||||
|
||||
Reference in New Issue
Block a user