surfaces/adapter/matrix/room_router.py

23 lines
671 B
Python

from __future__ import annotations
from adapter.matrix.store import get_room_meta, next_chat_id, set_room_meta
from core.store import StateStore
async def resolve_chat_id(store: StateStore, room_id: str, matrix_user_id: str) -> str:
meta = await get_room_meta(store, room_id)
if meta and meta.get("chat_id"):
return meta["chat_id"]
chat_id = await next_chat_id(store, matrix_user_id)
await set_room_meta(
store,
room_id,
{
"room_type": "chat",
"chat_id": chat_id,
"display_name": f"Чат {chat_id}",
"matrix_user_id": matrix_user_id,
},
)
return chat_id