feat: add platform chat id room metadata helpers
This commit is contained in:
parent
9bb93fbbda
commit
f3f9b10d6b
2 changed files with 36 additions and 0 deletions
|
|
@ -19,6 +19,19 @@ async def set_room_meta(store: StateStore, room_id: str, meta: dict) -> None:
|
|||
await store.set(f"{ROOM_META_PREFIX}{room_id}", meta)
|
||||
|
||||
|
||||
async def get_platform_chat_id(store: StateStore, room_id: str) -> str | None:
|
||||
meta = await get_room_meta(store, room_id)
|
||||
return meta.get("platform_chat_id") if meta else None
|
||||
|
||||
|
||||
async def set_platform_chat_id(
|
||||
store: StateStore, room_id: str, platform_chat_id: str
|
||||
) -> None:
|
||||
meta = await get_room_meta(store, room_id) or {}
|
||||
meta["platform_chat_id"] = platform_chat_id
|
||||
await set_room_meta(store, room_id, meta)
|
||||
|
||||
|
||||
async def get_user_meta(store: StateStore, matrix_user_id: str) -> dict | None:
|
||||
return await store.get(f"{USER_META_PREFIX}{matrix_user_id}")
|
||||
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@ import pytest
|
|||
from adapter.matrix.store import (
|
||||
clear_pending_confirm,
|
||||
get_pending_confirm,
|
||||
get_platform_chat_id,
|
||||
get_room_meta,
|
||||
get_room_state,
|
||||
get_skills_message_id,
|
||||
get_user_meta,
|
||||
next_chat_id,
|
||||
set_pending_confirm,
|
||||
set_platform_chat_id,
|
||||
set_room_meta,
|
||||
set_room_state,
|
||||
set_skills_message_id,
|
||||
|
|
@ -35,6 +37,27 @@ async def test_room_meta_roundtrip(store: InMemoryStore):
|
|||
assert await get_room_meta(store, "!r:m.org") == meta
|
||||
|
||||
|
||||
async def test_room_meta_roundtrip_with_platform_chat_id(store: InMemoryStore):
|
||||
meta = {
|
||||
"chat_id": "C1",
|
||||
"matrix_user_id": "@alice:example.org",
|
||||
"platform_chat_id": "chat-platform-1",
|
||||
}
|
||||
await set_room_meta(store, "!r:m.org", meta)
|
||||
saved = await get_room_meta(store, "!r:m.org")
|
||||
assert saved is not None
|
||||
assert saved["platform_chat_id"] == "chat-platform-1"
|
||||
|
||||
|
||||
async def test_platform_chat_id_helpers_roundtrip(store: InMemoryStore):
|
||||
await set_platform_chat_id(store, "!r:m.org", "chat-platform-1")
|
||||
|
||||
assert await get_platform_chat_id(store, "!r:m.org") == "chat-platform-1"
|
||||
assert await get_room_meta(store, "!r:m.org") == {
|
||||
"platform_chat_id": "chat-platform-1"
|
||||
}
|
||||
|
||||
|
||||
async def test_room_meta_missing(store: InMemoryStore):
|
||||
assert await get_room_meta(store, "!nonexistent:m.org") is None
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue