mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-04 20:05:16 +02:00
refactor(gateway): rename persistence models to external chat
This commit is contained in:
parent
f2d82234d4
commit
a57b741d5e
8 changed files with 274 additions and 323 deletions
|
|
@ -1,4 +1,4 @@
|
|||
"""Pairing code lifecycle for gateway bindings."""
|
||||
"""Pairing code lifecycle for external chat bindings."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
|
|
@ -8,7 +8,7 @@ from datetime import UTC, datetime, timedelta
|
|||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.db import GatewayBindingState, GatewayConversationBinding
|
||||
from app.db import ExternalChatBindingState, ExternalChatBinding
|
||||
|
||||
PAIRING_CODE_TTL = timedelta(minutes=10)
|
||||
|
||||
|
|
@ -30,19 +30,19 @@ async def redeem_pairing_code(
|
|||
external_display_name: str | None,
|
||||
external_username: str | None,
|
||||
external_metadata: dict | None = None,
|
||||
) -> GatewayConversationBinding | None:
|
||||
) -> ExternalChatBinding | None:
|
||||
result = await session.execute(
|
||||
select(GatewayConversationBinding).where(
|
||||
GatewayConversationBinding.pairing_code == code,
|
||||
GatewayConversationBinding.state == GatewayBindingState.PENDING,
|
||||
GatewayConversationBinding.pairing_code_expires_at > datetime.now(UTC),
|
||||
select(ExternalChatBinding).where(
|
||||
ExternalChatBinding.pairing_code == code,
|
||||
ExternalChatBinding.state == ExternalChatBindingState.PENDING,
|
||||
ExternalChatBinding.pairing_code_expires_at > datetime.now(UTC),
|
||||
)
|
||||
)
|
||||
binding = result.scalars().first()
|
||||
if binding is None:
|
||||
return None
|
||||
|
||||
binding.state = GatewayBindingState.BOUND
|
||||
binding.state = ExternalChatBindingState.BOUND
|
||||
binding.pairing_code = None
|
||||
binding.pairing_code_expires_at = None
|
||||
binding.external_peer_id = external_peer_id
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue