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,
|
||||
InviteMemberEvent,
|
||||
OlmUnverifiedDeviceError,
|
||||
KeyVerificationRequest,
|
||||
KeyVerificationStart,
|
||||
KeyVerificationKey,
|
||||
KeyVerificationMac,
|
||||
KeyVerificationCancel,
|
||||
KeyVerificationDone,
|
||||
ToDeviceError,
|
||||
UnknownToDeviceEvent,
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
@ -143,11 +142,10 @@ def get_requestable_groups(username: str) -> tuple[bool, str]:
|
|||
# ------------------------------------------------------------------------------
|
||||
async def on_to_device(client: AsyncClient, event):
|
||||
"""Handles incoming interactive SAS key verification events automatically."""
|
||||
if isinstance(event, KeyVerificationRequest):
|
||||
print(f"Received verification request from {event.sender} ({event.from_device}). Accepting request...")
|
||||
resp = await client.accept_key_verification(event.transaction_id)
|
||||
if isinstance(resp, ToDeviceError):
|
||||
print(f"Failed to accept verification request: {resp}")
|
||||
if isinstance(event, UnknownToDeviceEvent):
|
||||
if event.type == "m.key.verification.request":
|
||||
from_device = event.source.get("content", {}).get("from_device", "unknown")
|
||||
print(f"Received m.key.verification.request from {event.sender} ({from_device}).")
|
||||
|
||||
elif isinstance(event, KeyVerificationStart):
|
||||
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):
|
||||
print(f"Failed to confirm SAS: {resp}")
|
||||
|
||||
elif isinstance(event, (KeyVerificationMac, KeyVerificationDone)):
|
||||
print(f"✅ Key verification successfully completed with {event.sender} ({event.from_device})!")
|
||||
elif isinstance(event, (KeyVerificationMac, KeyVerificationCancel)):
|
||||
print(f"Key verification event ({event.__class__.__name__}) received from {event.sender}.")
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
|
@ -391,12 +389,11 @@ async def main():
|
|||
client.add_to_device_callback(
|
||||
lambda event: on_to_device(client, event),
|
||||
(
|
||||
KeyVerificationRequest,
|
||||
KeyVerificationStart,
|
||||
KeyVerificationKey,
|
||||
KeyVerificationMac,
|
||||
KeyVerificationCancel,
|
||||
KeyVerificationDone,
|
||||
UnknownToDeviceEvent,
|
||||
),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue