feat(chats): add per-user chat archive support

This commit is contained in:
2026-03-08 09:53:28 +03:00
parent 76f008d635
commit fdf973eeab
10 changed files with 248 additions and 16 deletions

View File

@@ -32,6 +32,7 @@ from app.chats.service import (
remove_chat_member_for_user,
serialize_chat_for_user,
serialize_chats_for_user,
set_chat_archived_for_user,
update_chat_member_role_for_user,
update_chat_notification_settings_for_user,
update_chat_title_for_user,
@@ -47,10 +48,18 @@ async def list_chats(
limit: int = 50,
before_id: int | None = None,
query: str | None = None,
archived: bool = False,
db: AsyncSession = Depends(get_db),
current_user: User = Depends(get_current_user),
) -> list[ChatRead]:
chats = await get_chats_for_user(db, user_id=current_user.id, limit=limit, before_id=before_id, query=query)
chats = await get_chats_for_user(
db,
user_id=current_user.id,
limit=limit,
before_id=before_id,
query=query,
archived=archived,
)
return await serialize_chats_for_user(db, user_id=current_user.id, chats=chats)
@@ -228,3 +237,23 @@ async def update_chat_notifications(
user_id=current_user.id,
payload=payload,
)
@router.post("/{chat_id}/archive", response_model=ChatRead)
async def archive_chat(
chat_id: int,
db: AsyncSession = Depends(get_db),
current_user: User = Depends(get_current_user),
) -> ChatRead:
chat = await set_chat_archived_for_user(db, chat_id=chat_id, user_id=current_user.id, archived=True)
return await serialize_chat_for_user(db, user_id=current_user.id, chat=chat)
@router.post("/{chat_id}/unarchive", response_model=ChatRead)
async def unarchive_chat(
chat_id: int,
db: AsyncSession = Depends(get_db),
current_user: User = Depends(get_current_user),
) -> ChatRead:
chat = await set_chat_archived_for_user(db, chat_id=chat_id, user_id=current_user.id, archived=False)
return await serialize_chat_for_user(db, user_id=current_user.id, chat=chat)