client: Refactor out the to device event handling.

This commit is contained in:
Damir Jelić 2019-12-19 16:00:38 +01:00
parent d38825704d
commit f3014ec649

View File

@ -804,6 +804,23 @@ class PanClient(AsyncClient):
return body return body
def handle_to_device_from_sync_body(self, body):
to_device_events = body.get("to_device")
if not to_device_events or "events" not in to_device_events:
return
for event in to_device_events["events"]:
if event.get("type") != "m.room.encrypted":
continue
event = ToDeviceEvent.parse_encrypted_event(event)
if not isinstance(event, OlmEvent):
continue
self.olm.handle_to_device_event(event)
def decrypt_sync_body(self, body, ignore_failures=True): def decrypt_sync_body(self, body, ignore_failures=True):
# type: (Dict[Any, Any], bool) -> Dict[Any, Any] # type: (Dict[Any, Any], bool) -> Dict[Any, Any]
"""Go through a json sync response and decrypt megolm encrypted events. """Go through a json sync response and decrypt megolm encrypted events.
@ -815,15 +832,7 @@ class PanClient(AsyncClient):
""" """
logger.info("Decrypting sync") logger.info("Decrypting sync")
for event in body["to_device"]["events"]: self.handle_to_device_from_sync_body(body)
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: