Add lazy platform chat IDs for Matrix rooms
This commit is contained in:
parent
c666d908da
commit
9cb1657d21
2 changed files with 60 additions and 1 deletions
|
|
@ -28,6 +28,7 @@ from adapter.matrix.store import (
|
|||
clear_load_pending,
|
||||
get_load_pending,
|
||||
get_room_meta,
|
||||
set_platform_chat_id,
|
||||
set_room_meta,
|
||||
set_pending_confirm,
|
||||
)
|
||||
|
|
@ -138,6 +139,15 @@ class MatrixBot:
|
|||
self.client = client
|
||||
self.runtime = runtime
|
||||
|
||||
async def _ensure_platform_chat_id(self, room_id: str, room_meta: dict | None) -> None:
|
||||
if not room_meta:
|
||||
return
|
||||
if room_meta.get("redirect_room_id"):
|
||||
return
|
||||
if room_meta.get("platform_chat_id"):
|
||||
return
|
||||
await set_platform_chat_id(self.runtime.store, room_id, f"matrix:{room_id}")
|
||||
|
||||
async def on_room_message(self, room: MatrixRoom, event: RoomMessageText) -> None:
|
||||
if getattr(event, "sender", None) == self.client.user_id:
|
||||
return
|
||||
|
|
@ -177,6 +187,8 @@ class MatrixBot:
|
|||
user=sender,
|
||||
)
|
||||
return
|
||||
else:
|
||||
await self._ensure_platform_chat_id(room.room_id, room_meta)
|
||||
|
||||
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue