realtime(chats): update subscriptions on delete/leave chat actions
All checks were successful
CI / test (push) Successful in 41s
All checks were successful
CI / test (push) Successful in 41s
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user