feat(matrix): land QA follow-ups and refresh docs
- harden Matrix onboarding/chat lifecycle after manual QA - refresh README and Matrix docs to match current behavior - add local ignores for runtime artifacts and include current planning/report docs Closes #7 Closes #9 Closes #14
This commit is contained in:
parent
7fce4c9b3e
commit
6ced154124
35 changed files with 8380 additions and 67 deletions
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
from typing import Any, Awaitable, Callable
|
||||
|
||||
import structlog
|
||||
from nio.api import RoomVisibility
|
||||
from nio.responses import RoomCreateError
|
||||
|
||||
from adapter.matrix.store import get_user_meta, next_chat_id, set_room_meta
|
||||
|
|
@ -11,6 +12,10 @@ from core.protocol import IncomingCommand, OutgoingMessage
|
|||
logger = structlog.get_logger(__name__)
|
||||
|
||||
|
||||
def _is_unregistered_chat_id(chat_id: str) -> bool:
|
||||
return chat_id.startswith("unregistered:")
|
||||
|
||||
|
||||
async def _fallback_new_chat(
|
||||
event: IncomingCommand, auth_mgr, platform, chat_mgr, settings_mgr
|
||||
) -> list:
|
||||
|
|
@ -68,8 +73,9 @@ def make_handle_new_chat(
|
|||
|
||||
response = await client.room_create(
|
||||
name=room_name,
|
||||
visibility="private",
|
||||
visibility=RoomVisibility.private,
|
||||
is_direct=False,
|
||||
invite=[event.user_id],
|
||||
)
|
||||
if isinstance(response, RoomCreateError):
|
||||
logger.error(
|
||||
|
|
@ -90,7 +96,6 @@ def make_handle_new_chat(
|
|||
content={"via": [homeserver]},
|
||||
state_key=room_id,
|
||||
)
|
||||
await client.room_invite(room_id, event.user_id)
|
||||
|
||||
await set_room_meta(
|
||||
store,
|
||||
|
|
@ -141,11 +146,23 @@ def make_handle_rename(
|
|||
return [
|
||||
OutgoingMessage(chat_id=event.chat_id, text="Укажите название: !rename Название")
|
||||
]
|
||||
if _is_unregistered_chat_id(event.chat_id):
|
||||
return [
|
||||
OutgoingMessage(
|
||||
chat_id=event.chat_id,
|
||||
text="Этот чат не найден в локальном состоянии бота. Открой зарегистрированную комнату или создай новый чат через !new.",
|
||||
)
|
||||
]
|
||||
|
||||
new_name = " ".join(event.args)
|
||||
ctx = await chat_mgr.rename(event.chat_id, new_name, user_id=event.user_id)
|
||||
if client is not None and ctx.surface_ref:
|
||||
await client.room_set_name(ctx.surface_ref, new_name)
|
||||
await client.room_put_state(
|
||||
room_id=ctx.surface_ref,
|
||||
event_type="m.room.name",
|
||||
content={"name": new_name},
|
||||
state_key="",
|
||||
)
|
||||
|
||||
return [OutgoingMessage(chat_id=event.chat_id, text=f"Переименован в: {ctx.display_name}")]
|
||||
|
||||
|
|
@ -159,7 +176,19 @@ def make_handle_archive(
|
|||
async def handle_archive(
|
||||
event: IncomingCommand, auth_mgr, platform, chat_mgr, settings_mgr
|
||||
) -> list:
|
||||
if _is_unregistered_chat_id(event.chat_id):
|
||||
return [
|
||||
OutgoingMessage(
|
||||
chat_id=event.chat_id,
|
||||
text="Этот чат не найден в локальном состоянии бота. Создай новый чат через !new.",
|
||||
)
|
||||
]
|
||||
ctx = await chat_mgr.get(event.chat_id, user_id=event.user_id)
|
||||
if ctx is None:
|
||||
return [OutgoingMessage(chat_id=event.chat_id, text="Этот чат не найден.")]
|
||||
await chat_mgr.archive(event.chat_id, user_id=event.user_id)
|
||||
if client is not None and ctx.surface_ref:
|
||||
await client.room_leave(ctx.surface_ref)
|
||||
return [OutgoingMessage(chat_id=event.chat_id, text="Чат архивирован.")]
|
||||
|
||||
return handle_archive
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue