Files
ds-chat/backend/app/routers/webhooks.py
T
ksmithandClaude Sonnet 5 ed88eb0205 Fix desktop messages not appearing live until refocus (#59)
Desktop mode's focus gating (from #49) made losing OS focus send "leave"
for every open room, which stopped live message delivery to that room,
not just notification eligibility -- so a message wouldn't render until
the room was manually left and rejoined. Room join/leave is now gated on
visibility alone, matching the browser; notification eligibility gets its
own separate signal (a "focus"/"blur" WS frame tracked by a new
Redis-backed FocusPresence), so a connected-but-unfocused desktop member
still gets notified without losing live delivery.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-19 18:08:04 -06:00

30 lines
1.2 KiB
Python

from fastapi import APIRouter, Depends, HTTPException, Request
from sqlalchemy.ext.asyncio import AsyncSession
from app.database import get_db
from app.schemas.webhook import IncomingWebhookPost
from app.services.message_events import broadcast_new_message
from app.services.webhook_service import WebhookNotFoundError, post_via_webhook
router = APIRouter(prefix="/api/webhooks", tags=["webhooks"])
@router.post("/incoming/{token}", status_code=204)
async def incoming_webhook_endpoint(
token: str,
data: IncomingWebhookPost,
request: Request,
db: AsyncSession = Depends(get_db),
) -> None:
# No auth dependency at all -- the token in the URL is the credential,
# per ARCHITECTURE.md's incoming-webhook design.
try:
message, room, sender = await post_via_webhook(db, token, data.content)
except WebhookNotFoundError:
raise HTTPException(status_code=404, detail="Unknown webhook")
broadcaster = request.app.state.broadcaster
presence = request.app.state.presence
focus_presence = request.app.state.focus_presence
await broadcast_new_message(db, broadcaster, presence, focus_presence, room.id, message, sender)