feat(invites): add group/channel invite links and join by token

This commit is contained in:
2026-03-08 09:58:55 +03:00
parent cc70394960
commit f01bbda14e
11 changed files with 247 additions and 6 deletions

View File

@@ -7,6 +7,8 @@ from app.chats.schemas import (
ChatDetailRead,
ChatDiscoverRead,
ChatDeleteRequest,
ChatInviteLinkRead,
ChatJoinByInviteRequest,
ChatMemberAddRequest,
ChatMemberRead,
ChatMemberRoleUpdateRequest,
@@ -19,6 +21,7 @@ from app.chats.schemas import (
from app.chats.service import (
add_chat_member_for_user,
create_chat_for_user,
create_chat_invite_link_for_user,
clear_chat_for_user,
delete_chat_for_user,
discover_public_chats_for_user,
@@ -27,6 +30,7 @@ from app.chats.service import (
get_chat_notification_settings_for_user,
get_chats_for_user,
join_public_chat_for_user,
join_chat_by_invite_for_user,
leave_chat_for_user,
pin_chat_message_for_user,
remove_chat_member_for_user,
@@ -278,3 +282,22 @@ async def unpin_chat(
) -> ChatRead:
chat = await set_chat_pinned_for_user(db, chat_id=chat_id, user_id=current_user.id, pinned=False)
return await serialize_chat_for_user(db, user_id=current_user.id, chat=chat)
@router.post("/{chat_id}/invite-link", response_model=ChatInviteLinkRead)
async def create_invite_link(
chat_id: int,
db: AsyncSession = Depends(get_db),
current_user: User = Depends(get_current_user),
) -> ChatInviteLinkRead:
return await create_chat_invite_link_for_user(db, chat_id=chat_id, user_id=current_user.id)
@router.post("/join-by-invite", response_model=ChatRead)
async def join_by_invite(
payload: ChatJoinByInviteRequest,
db: AsyncSession = Depends(get_db),
current_user: User = Depends(get_current_user),
) -> ChatRead:
chat = await join_chat_by_invite_for_user(db, user_id=current_user.id, payload=payload)
return await serialize_chat_for_user(db, user_id=current_user.id, chat=chat)