feat(core): clear saved chat and add message deletion scopes
Some checks failed
CI / test (push) Failing after 26s

backend:

- add message_hidden table for per-user message hiding

- support DELETE /messages/{id}?for_all=true|false

- implement delete-for-me vs delete-for-all logic by chat type/permissions

- add POST /chats/{chat_id}/clear and route saved chat deletion to clear

web:

- saved messages action changed from delete to clear

- message context menu now supports delete modal: for me / for everyone

- add local store helpers removeMessage/clearChatMessages

- include realtime stability improvements and app error boundary
This commit is contained in:
2026-03-08 01:13:20 +03:00
parent a42f97962b
commit 7f15edcb4e
15 changed files with 486 additions and 77 deletions

View File

@@ -5,7 +5,13 @@ from sqlalchemy.ext.asyncio import AsyncSession
from app.chats import repository
from app.chats.models import Chat, ChatMember, ChatMemberRole, ChatType
from app.chats.schemas import ChatCreateRequest, ChatDeleteRequest, ChatDiscoverRead, ChatPinMessageRequest, ChatRead, ChatTitleUpdateRequest
from app.messages.repository import get_message_by_id
from app.messages.repository import (
delete_messages_in_chat,
get_hidden_message,
get_message_by_id,
hide_message_for_user,
list_chat_message_ids,
)
from app.users.repository import get_user_by_id
@@ -349,6 +355,9 @@ async def join_public_chat_for_user(db: AsyncSession, *, chat_id: int, user_id:
async def delete_chat_for_user(db: AsyncSession, *, chat_id: int, user_id: int, payload: ChatDeleteRequest) -> None:
chat, membership = await _get_chat_and_membership(db, chat_id=chat_id, user_id=user_id)
if chat.is_saved:
await clear_chat_for_user(db, chat_id=chat_id, user_id=user_id)
return
delete_for_all = (payload.for_all and not chat.is_saved) or chat.type == ChatType.CHANNEL
if delete_for_all:
if chat.type in {ChatType.GROUP, ChatType.CHANNEL} and membership.role not in {ChatMemberRole.OWNER, ChatMemberRole.ADMIN}:
@@ -358,3 +367,18 @@ async def delete_chat_for_user(db: AsyncSession, *, chat_id: int, user_id: int,
return
await repository.delete_chat_member(db, membership)
await db.commit()
async def clear_chat_for_user(db: AsyncSession, *, chat_id: int, user_id: int) -> None:
chat, _membership = await _get_chat_and_membership(db, chat_id=chat_id, user_id=user_id)
if chat.is_saved:
await delete_messages_in_chat(db, chat_id=chat_id)
await db.commit()
return
message_ids = await list_chat_message_ids(db, chat_id=chat_id)
for message_id in message_ids:
already_hidden = await get_hidden_message(db, message_id=message_id, user_id=user_id)
if already_hidden:
continue
await hide_message_for_user(db, message_id=message_id, user_id=user_id)
await db.commit()