feat(invites): add group/channel invite links and join by token
This commit is contained in:
@@ -2,7 +2,7 @@ from sqlalchemy import Select, String, func, or_, select
|
||||
from sqlalchemy.orm import aliased
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.chats.models import Chat, ChatMember, ChatMemberRole, ChatNotificationSetting, ChatType, ChatUserSetting
|
||||
from app.chats.models import Chat, ChatInviteLink, ChatMember, ChatMemberRole, ChatNotificationSetting, ChatType, ChatUserSetting
|
||||
from app.messages.models import Message, MessageHidden, MessageReceipt
|
||||
|
||||
|
||||
@@ -320,3 +320,25 @@ async def upsert_chat_pinned_setting(
|
||||
db.add(setting)
|
||||
await db.flush()
|
||||
return setting
|
||||
|
||||
|
||||
async def create_chat_invite_link(
|
||||
db: AsyncSession,
|
||||
*,
|
||||
chat_id: int,
|
||||
creator_user_id: int,
|
||||
token: str,
|
||||
) -> ChatInviteLink:
|
||||
link = ChatInviteLink(chat_id=chat_id, creator_user_id=creator_user_id, token=token, is_active=True)
|
||||
db.add(link)
|
||||
await db.flush()
|
||||
return link
|
||||
|
||||
|
||||
async def get_active_chat_invite_by_token(db: AsyncSession, *, token: str) -> ChatInviteLink | None:
|
||||
result = await db.execute(
|
||||
select(ChatInviteLink)
|
||||
.where(ChatInviteLink.token == token, ChatInviteLink.is_active.is_(True))
|
||||
.limit(1)
|
||||
)
|
||||
return result.scalar_one_or_none()
|
||||
|
||||
Reference in New Issue
Block a user