fix(01-05): align matrix confirmation scope with user and room
- carry Matrix room_id through command callbacks - persist pending confirmations by user_id and room_id
This commit is contained in:
parent
97a3dc35ea
commit
35695e043f
4 changed files with 62 additions and 25 deletions
|
|
@ -51,13 +51,26 @@ async def next_chat_id(store: StateStore, matrix_user_id: str) -> str:
|
|||
return f"C{index}"
|
||||
|
||||
|
||||
async def get_pending_confirm(store: StateStore, room_id: str) -> dict | None:
|
||||
return await store.get(f"{PENDING_CONFIRM_PREFIX}{room_id}")
|
||||
def _pending_confirm_key(user_id: str, room_id: str | None = None) -> str:
|
||||
if room_id is None:
|
||||
return f"{PENDING_CONFIRM_PREFIX}{user_id}"
|
||||
return f"{PENDING_CONFIRM_PREFIX}{user_id}:{room_id}"
|
||||
|
||||
async def get_pending_confirm(
|
||||
store: StateStore, user_id: str, room_id: str | None = None
|
||||
) -> dict | None:
|
||||
return await store.get(_pending_confirm_key(user_id, room_id))
|
||||
|
||||
async def set_pending_confirm(
|
||||
store: StateStore, user_id: str, room_id: str | dict, meta: dict | None = None
|
||||
) -> None:
|
||||
if meta is None:
|
||||
await store.set(_pending_confirm_key(user_id), room_id)
|
||||
return
|
||||
await store.set(_pending_confirm_key(user_id, str(room_id)), meta)
|
||||
|
||||
|
||||
async def set_pending_confirm(store: StateStore, room_id: str, meta: dict) -> None:
|
||||
await store.set(f"{PENDING_CONFIRM_PREFIX}{room_id}", meta)
|
||||
|
||||
|
||||
async def clear_pending_confirm(store: StateStore, room_id: str) -> None:
|
||||
await store.delete(f"{PENDING_CONFIRM_PREFIX}{room_id}")
|
||||
async def clear_pending_confirm(
|
||||
store: StateStore, user_id: str, room_id: str | None = None
|
||||
) -> None:
|
||||
await store.delete(_pending_confirm_key(user_id, room_id))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue