feat(01-02): convert matrix archive and rename handlers to factories
- register archive and rename as client-aware closure handlers - rename matrix rooms via stored surface_ref when a client is available - keep archive scoped to core chat state for phase 1
This commit is contained in:
parent
c8770da345
commit
b7a04b6cf1
2 changed files with 35 additions and 14 deletions
|
|
@ -1,10 +1,10 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from adapter.matrix.handlers.chat import (
|
||||
handle_archive,
|
||||
handle_list_chats,
|
||||
make_handle_archive,
|
||||
make_handle_new_chat,
|
||||
handle_rename,
|
||||
make_handle_rename,
|
||||
)
|
||||
from adapter.matrix.handlers.confirm import handle_cancel, handle_confirm
|
||||
from adapter.matrix.handlers.settings import (
|
||||
|
|
@ -25,8 +25,8 @@ from core.protocol import IncomingCallback, IncomingCommand
|
|||
def register_matrix_handlers(dispatcher: EventDispatcher, client=None, store=None) -> None:
|
||||
dispatcher.register(IncomingCommand, "new", make_handle_new_chat(client, store))
|
||||
dispatcher.register(IncomingCommand, "chats", handle_list_chats)
|
||||
dispatcher.register(IncomingCommand, "rename", handle_rename)
|
||||
dispatcher.register(IncomingCommand, "archive", handle_archive)
|
||||
dispatcher.register(IncomingCommand, "rename", make_handle_rename(client, store))
|
||||
dispatcher.register(IncomingCommand, "archive", make_handle_archive(client, store))
|
||||
dispatcher.register(IncomingCommand, "settings", handle_settings)
|
||||
dispatcher.register(IncomingCommand, "settings_skills", handle_settings_skills)
|
||||
dispatcher.register(IncomingCommand, "settings_connectors", handle_settings_connectors)
|
||||
|
|
|
|||
|
|
@ -130,15 +130,36 @@ async def handle_list_chats(
|
|||
return [OutgoingMessage(chat_id=event.chat_id, text="\n".join(lines))]
|
||||
|
||||
|
||||
async def handle_rename(event: IncomingCommand, auth_mgr, platform, chat_mgr, settings_mgr) -> list:
|
||||
if not event.args:
|
||||
return [OutgoingMessage(chat_id=event.chat_id, text="Укажите название: !rename Название")]
|
||||
ctx = await chat_mgr.rename(event.chat_id, " ".join(event.args), user_id=event.user_id)
|
||||
return [OutgoingMessage(chat_id=event.chat_id, text=f"Переименован в: {ctx.display_name}")]
|
||||
def make_handle_rename(
|
||||
client: Any | None,
|
||||
store: Any | None,
|
||||
) -> Callable[..., Awaitable[list]]:
|
||||
async def handle_rename(
|
||||
event: IncomingCommand, auth_mgr, platform, chat_mgr, settings_mgr
|
||||
) -> list:
|
||||
if not event.args:
|
||||
return [
|
||||
OutgoingMessage(chat_id=event.chat_id, text="Укажите название: !rename Название")
|
||||
]
|
||||
|
||||
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)
|
||||
|
||||
return [OutgoingMessage(chat_id=event.chat_id, text=f"Переименован в: {ctx.display_name}")]
|
||||
|
||||
return handle_rename
|
||||
|
||||
|
||||
async def handle_archive(
|
||||
event: IncomingCommand, auth_mgr, platform, chat_mgr, settings_mgr
|
||||
) -> list:
|
||||
await chat_mgr.archive(event.chat_id, user_id=event.user_id)
|
||||
return [OutgoingMessage(chat_id=event.chat_id, text="Чат архивирован.")]
|
||||
def make_handle_archive(
|
||||
client: Any | None,
|
||||
store: Any | None,
|
||||
) -> Callable[..., Awaitable[list]]:
|
||||
async def handle_archive(
|
||||
event: IncomingCommand, auth_mgr, platform, chat_mgr, settings_mgr
|
||||
) -> list:
|
||||
await chat_mgr.archive(event.chat_id, user_id=event.user_id)
|
||||
return [OutgoingMessage(chat_id=event.chat_id, text="Чат архивирован.")]
|
||||
|
||||
return handle_archive
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue