35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from __future__ import annotations
|
|
from pathlib import Path
|
|
from fastapi import APIRouter, Depends, Request
|
|
from fastapi.responses import HTMLResponse, RedirectResponse
|
|
from fastapi.templating import Jinja2Templates
|
|
|
|
from chat.web.bots import get_conn
|
|
from chat.state.world import list_chats
|
|
from chat.state.entities import get_bot
|
|
|
|
TEMPLATES = Jinja2Templates(directory=str(Path(__file__).resolve().parent.parent / "templates"))
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/", include_in_schema=False)
|
|
async def home():
|
|
return RedirectResponse(url="/chats", status_code=303)
|
|
|
|
|
|
@router.get("/chats", response_class=HTMLResponse)
|
|
async def chats_list(request: Request, conn=Depends(get_conn)):
|
|
chats = list_chats(conn)
|
|
# Annotate each chat with the host bot's name for display.
|
|
for ch in chats:
|
|
bot = get_bot(conn, ch["host_bot_id"])
|
|
ch["host_bot_name"] = bot["name"] if bot else ch["host_bot_id"]
|
|
# Last-message snippet and last-played-at are blank in v1; T19 fills them.
|
|
ch["last_message_snippet"] = ""
|
|
ch["last_played_at"] = None
|
|
return TEMPLATES.TemplateResponse(request, "chat_list.html", {
|
|
"chats": chats,
|
|
"active_nav": "chats",
|
|
})
|