Some modern events haven't been properly handled by nio. Use an UnknownToDeviceEvent and key off of m.key.verification instead
This commit is contained in:
parent
4b09b7ff43
commit
bdede4dbf4
1 changed files with 8 additions and 11 deletions
|
|
@ -12,13 +12,12 @@ from nio import (
|
||||||
RoomSendResponse,
|
RoomSendResponse,
|
||||||
InviteMemberEvent,
|
InviteMemberEvent,
|
||||||
OlmUnverifiedDeviceError,
|
OlmUnverifiedDeviceError,
|
||||||
KeyVerificationRequest,
|
|
||||||
KeyVerificationStart,
|
KeyVerificationStart,
|
||||||
KeyVerificationKey,
|
KeyVerificationKey,
|
||||||
KeyVerificationMac,
|
KeyVerificationMac,
|
||||||
KeyVerificationCancel,
|
KeyVerificationCancel,
|
||||||
KeyVerificationDone,
|
|
||||||
ToDeviceError,
|
ToDeviceError,
|
||||||
|
UnknownToDeviceEvent,
|
||||||
)
|
)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
@ -143,11 +142,10 @@ def get_requestable_groups(username: str) -> tuple[bool, str]:
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
async def on_to_device(client: AsyncClient, event):
|
async def on_to_device(client: AsyncClient, event):
|
||||||
"""Handles incoming interactive SAS key verification events automatically."""
|
"""Handles incoming interactive SAS key verification events automatically."""
|
||||||
if isinstance(event, KeyVerificationRequest):
|
if isinstance(event, UnknownToDeviceEvent):
|
||||||
print(f"Received verification request from {event.sender} ({event.from_device}). Accepting request...")
|
if event.type == "m.key.verification.request":
|
||||||
resp = await client.accept_key_verification(event.transaction_id)
|
from_device = event.source.get("content", {}).get("from_device", "unknown")
|
||||||
if isinstance(resp, ToDeviceError):
|
print(f"Received m.key.verification.request from {event.sender} ({from_device}).")
|
||||||
print(f"Failed to accept verification request: {resp}")
|
|
||||||
|
|
||||||
elif isinstance(event, KeyVerificationStart):
|
elif isinstance(event, KeyVerificationStart):
|
||||||
print(f"Received key verification start from {event.sender} ({event.from_device}). Accepting start...")
|
print(f"Received key verification start from {event.sender} ({event.from_device}). Accepting start...")
|
||||||
|
|
@ -161,8 +159,8 @@ async def on_to_device(client: AsyncClient, event):
|
||||||
if isinstance(resp, ToDeviceError):
|
if isinstance(resp, ToDeviceError):
|
||||||
print(f"Failed to confirm SAS: {resp}")
|
print(f"Failed to confirm SAS: {resp}")
|
||||||
|
|
||||||
elif isinstance(event, (KeyVerificationMac, KeyVerificationDone)):
|
elif isinstance(event, (KeyVerificationMac, KeyVerificationCancel)):
|
||||||
print(f"✅ Key verification successfully completed with {event.sender} ({event.from_device})!")
|
print(f"Key verification event ({event.__class__.__name__}) received from {event.sender}.")
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
@ -391,12 +389,11 @@ async def main():
|
||||||
client.add_to_device_callback(
|
client.add_to_device_callback(
|
||||||
lambda event: on_to_device(client, event),
|
lambda event: on_to_device(client, event),
|
||||||
(
|
(
|
||||||
KeyVerificationRequest,
|
|
||||||
KeyVerificationStart,
|
KeyVerificationStart,
|
||||||
KeyVerificationKey,
|
KeyVerificationKey,
|
||||||
KeyVerificationMac,
|
KeyVerificationMac,
|
||||||
KeyVerificationCancel,
|
KeyVerificationCancel,
|
||||||
KeyVerificationDone,
|
UnknownToDeviceEvent,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue