fix: make matrix entry-room bootstrap idempotent
This commit is contained in:
parent
17d580096b
commit
c666d908da
2 changed files with 65 additions and 0 deletions
|
|
@ -28,6 +28,7 @@ from adapter.matrix.store import (
|
|||
clear_load_pending,
|
||||
get_load_pending,
|
||||
get_room_meta,
|
||||
set_room_meta,
|
||||
set_pending_confirm,
|
||||
)
|
||||
from core.auth import AuthManager
|
||||
|
|
@ -154,6 +155,28 @@ class MatrixBot:
|
|||
if outgoing:
|
||||
await self._send_all(room.room_id, outgoing)
|
||||
return
|
||||
elif room_meta.get("redirect_room_id"):
|
||||
redirect_room_id = room_meta["redirect_room_id"]
|
||||
redirect_chat_id = room_meta.get("redirect_chat_id", "рабочий чат")
|
||||
await self._send_all(
|
||||
room.room_id,
|
||||
[
|
||||
OutgoingMessage(
|
||||
chat_id=room.room_id,
|
||||
text=(
|
||||
f"Рабочий чат уже создан: {redirect_chat_id}. "
|
||||
"Открой приглашённую комнату для продолжения."
|
||||
),
|
||||
)
|
||||
],
|
||||
)
|
||||
logger.info(
|
||||
"matrix_redirect_entry_room",
|
||||
room_id=room.room_id,
|
||||
redirect_room_id=redirect_room_id,
|
||||
user=sender,
|
||||
)
|
||||
return
|
||||
|
||||
chat_id = await resolve_chat_id(self.runtime.store, room.room_id, sender)
|
||||
incoming = from_room_event(event, room_id=room.room_id, chat_id=chat_id)
|
||||
|
|
@ -218,6 +241,15 @@ class MatrixBot:
|
|||
"m.room.message",
|
||||
{"msgtype": "m.text", "body": welcome},
|
||||
)
|
||||
await set_room_meta(
|
||||
self.runtime.store,
|
||||
room.room_id,
|
||||
{
|
||||
"matrix_user_id": sender,
|
||||
"redirect_room_id": created["chat_room_id"],
|
||||
"redirect_chat_id": created["chat_id"],
|
||||
},
|
||||
)
|
||||
return [
|
||||
OutgoingMessage(
|
||||
chat_id=room.room_id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue