realtime(chats): update subscriptions on delete/leave chat actions
All checks were successful
CI / test (push) Successful in 41s

This commit is contained in:
2026-03-08 19:40:03 +03:00
parent 8965dc93fd
commit a896568c53
2 changed files with 15 additions and 1 deletions

View File

@@ -19,6 +19,8 @@ from app.chats.schemas import (
ChatRead,
ChatTitleUpdateRequest,
)
from app.chats import repository as chats_repository
from app.chats.models import ChatType
from app.chats.service import (
add_chat_member_for_user,
ban_chat_member_for_user,
@@ -250,7 +252,19 @@ async def delete_chat(
db: AsyncSession = Depends(get_db),
current_user: User = Depends(get_current_user),
) -> None:
chat_before_delete = await chats_repository.get_chat_by_id(db, chat_id)
delete_for_all = bool(
chat_before_delete
and (
(for_all and not chat_before_delete.is_saved)
or (chat_before_delete.type == ChatType.CHANNEL and not chat_before_delete.is_saved)
)
)
await delete_chat_for_user(db, chat_id=chat_id, user_id=current_user.id, payload=ChatDeleteRequest(for_all=for_all))
if chat_before_delete and not chat_before_delete.is_saved:
realtime_gateway.remove_chat_subscription(chat_id=chat_id, user_id=current_user.id)
if not delete_for_all:
await realtime_gateway.publish_chat_updated(chat_id=chat_id)
@router.post("/{chat_id}/clear", status_code=status.HTTP_204_NO_CONTENT)

View File

@@ -40,7 +40,7 @@ Legend:
31. Privacy - `PARTIAL` (avatar/last-seen/group-invites + PM policy `everyone|contacts|nobody`; policy behavior covered by integration tests, remaining UX/matrix hardening)
32. Security - `PARTIAL` (sessions + revoke + 2FA base + access-session visibility; revoke-all now force-disconnects active realtime sessions; 2FA setup now blocked after enable to prevent secret re-issuance; one-time recovery codes added; UX polish ongoing)
33. Realtime Events - `DONE` (connect/disconnect/send/receive/typing/read/delivered/online/offline + chat/message updates)
34. Sync - `PARTIAL` (cross-device via backend state + realtime; reconciliation improved for loaded chats/messages, chat-info panel now hot-refreshes on `chat_updated`)
34. Sync - `PARTIAL` (cross-device via backend state + realtime; reconciliation improved for loaded chats/messages, chat-info panel hot-refreshes on `chat_updated`, delete/leave now updates realtime subscriptions)
35. Additional - `PARTIAL` (drafts/link preview partial/autoload media basic)
## Current Focus to reach ~80%