client: Decrypt to-device events from the client sync stream.

This commit is contained in:
Damir Jelić 2019-12-09 10:43:16 +01:00
parent e2497bca38
commit d38825704d

View File

@ -26,12 +26,14 @@ from nio import (
ClientConfig, ClientConfig,
EncryptionError, EncryptionError,
Event, Event,
ToDeviceEvent,
KeysQueryResponse, KeysQueryResponse,
KeyVerificationEvent, KeyVerificationEvent,
KeyVerificationKey, KeyVerificationKey,
KeyVerificationMac, KeyVerificationMac,
KeyVerificationStart, KeyVerificationStart,
LocalProtocolError, LocalProtocolError,
OlmEvent,
MegolmEvent, MegolmEvent,
RoomContextError, RoomContextError,
RoomEncryptedMedia, RoomEncryptedMedia,
@ -812,6 +814,17 @@ class PanClient(AsyncClient):
Returns the json response with decrypted events. Returns the json response with decrypted events.
""" """
logger.info("Decrypting sync") logger.info("Decrypting sync")
for event in body["to_device"]["events"]:
if event["type"] != "m.room.encrypted":
continue
event = ToDeviceEvent.parse_encrypted_event(event)
if not isinstance(event, OlmEvent):
continue
self.olm.handle_to_device_event(event)
for room_id, room_dict in body["rooms"]["join"].items(): for room_id, room_dict in body["rooms"]["join"].items():
try: try:
if not self.rooms[room_id].encrypted: if not self.rooms[room_id].encrypted: