feat: realtime sync, settings UX and chat list improvements
Some checks failed
CI / test (push) Failing after 21s
Some checks failed
CI / test (push) Failing after 21s
- add chat_updated realtime event and dynamic chat subscriptions - auto-join invite links in web app - implement Telegram-like settings panel (general/notifications/privacy) - add browser notification preferences and keyboard send mode - improve chat list with last message preview/time and online badge - rework chat members UI with context actions and role crowns
This commit is contained in:
@@ -43,6 +43,7 @@ from app.chats.service import (
|
||||
update_chat_title_for_user,
|
||||
)
|
||||
from app.database.session import get_db
|
||||
from app.realtime.service import realtime_gateway
|
||||
from app.users.models import User
|
||||
|
||||
router = APIRouter(prefix="/chats", tags=["chats"])
|
||||
@@ -94,6 +95,7 @@ async def create_chat(
|
||||
current_user: User = Depends(get_current_user),
|
||||
) -> ChatRead:
|
||||
chat = await create_chat_for_user(db, creator_id=current_user.id, payload=payload)
|
||||
realtime_gateway.add_chat_subscription(chat_id=chat.id, user_id=current_user.id)
|
||||
return await serialize_chat_for_user(db, user_id=current_user.id, chat=chat)
|
||||
|
||||
|
||||
@@ -104,6 +106,8 @@ async def join_chat(
|
||||
current_user: User = Depends(get_current_user),
|
||||
) -> ChatRead:
|
||||
chat = await join_public_chat_for_user(db, chat_id=chat_id, user_id=current_user.id)
|
||||
realtime_gateway.add_chat_subscription(chat_id=chat.id, user_id=current_user.id)
|
||||
await realtime_gateway.publish_chat_updated(chat_id=chat.id)
|
||||
return await serialize_chat_for_user(db, user_id=current_user.id, chat=chat)
|
||||
|
||||
|
||||
@@ -131,6 +135,7 @@ async def update_chat_title(
|
||||
current_user: User = Depends(get_current_user),
|
||||
) -> ChatRead:
|
||||
chat = await update_chat_title_for_user(db, chat_id=chat_id, user_id=current_user.id, payload=payload)
|
||||
await realtime_gateway.publish_chat_updated(chat_id=chat.id)
|
||||
return await serialize_chat_for_user(db, user_id=current_user.id, chat=chat)
|
||||
|
||||
|
||||
@@ -151,7 +156,10 @@ async def add_chat_member(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
) -> ChatMemberRead:
|
||||
return await add_chat_member_for_user(db, chat_id=chat_id, actor_user_id=current_user.id, target_user_id=payload.user_id)
|
||||
member = await add_chat_member_for_user(db, chat_id=chat_id, actor_user_id=current_user.id, target_user_id=payload.user_id)
|
||||
realtime_gateway.add_chat_subscription(chat_id=chat_id, user_id=payload.user_id)
|
||||
await realtime_gateway.publish_chat_updated(chat_id=chat_id)
|
||||
return member
|
||||
|
||||
|
||||
@router.patch("/{chat_id}/members/{user_id}/role", response_model=ChatMemberRead)
|
||||
@@ -162,13 +170,15 @@ async def update_chat_member_role(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
) -> ChatMemberRead:
|
||||
return await update_chat_member_role_for_user(
|
||||
member = await update_chat_member_role_for_user(
|
||||
db,
|
||||
chat_id=chat_id,
|
||||
actor_user_id=current_user.id,
|
||||
target_user_id=user_id,
|
||||
role=payload.role,
|
||||
)
|
||||
await realtime_gateway.publish_chat_updated(chat_id=chat_id)
|
||||
return member
|
||||
|
||||
|
||||
@router.delete("/{chat_id}/members/{user_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -179,6 +189,8 @@ async def remove_chat_member(
|
||||
current_user: User = Depends(get_current_user),
|
||||
) -> None:
|
||||
await remove_chat_member_for_user(db, chat_id=chat_id, actor_user_id=current_user.id, target_user_id=user_id)
|
||||
realtime_gateway.remove_chat_subscription(chat_id=chat_id, user_id=user_id)
|
||||
await realtime_gateway.publish_chat_updated(chat_id=chat_id)
|
||||
|
||||
|
||||
@router.post("/{chat_id}/leave", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -188,6 +200,8 @@ async def leave_chat(
|
||||
current_user: User = Depends(get_current_user),
|
||||
) -> None:
|
||||
await leave_chat_for_user(db, chat_id=chat_id, user_id=current_user.id)
|
||||
realtime_gateway.remove_chat_subscription(chat_id=chat_id, user_id=current_user.id)
|
||||
await realtime_gateway.publish_chat_updated(chat_id=chat_id)
|
||||
|
||||
|
||||
@router.delete("/{chat_id}", status_code=status.HTTP_204_NO_CONTENT)
|
||||
@@ -217,6 +231,7 @@ async def pin_chat_message(
|
||||
current_user: User = Depends(get_current_user),
|
||||
) -> ChatRead:
|
||||
chat = await pin_chat_message_for_user(db, chat_id=chat_id, user_id=current_user.id, payload=payload)
|
||||
await realtime_gateway.publish_chat_updated(chat_id=chat.id)
|
||||
return await serialize_chat_for_user(db, user_id=current_user.id, chat=chat)
|
||||
|
||||
|
||||
@@ -300,4 +315,6 @@ async def join_by_invite(
|
||||
current_user: User = Depends(get_current_user),
|
||||
) -> ChatRead:
|
||||
chat = await join_chat_by_invite_for_user(db, user_id=current_user.id, payload=payload)
|
||||
realtime_gateway.add_chat_subscription(chat_id=chat.id, user_id=current_user.id)
|
||||
await realtime_gateway.publish_chat_updated(chat_id=chat.id)
|
||||
return await serialize_chat_for_user(db, user_id=current_user.id, chat=chat)
|
||||
|
||||
Reference in New Issue
Block a user