From 14c8377a2fa3fc42eb46660b66b1dad2e4ff181e Mon Sep 17 00:00:00 2001 From: Sorunome Date: Sun, 26 Jul 2020 07:54:03 +0200 Subject: [PATCH] make sure that no http requests are done inside of /sync --- lib/encryption/encryption.dart | 10 +++++++--- lib/encryption/key_manager.dart | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/encryption/encryption.dart b/lib/encryption/encryption.dart index 940f4fa..4470285 100644 --- a/lib/encryption/encryption.dart +++ b/lib/encryption/encryption.dart @@ -72,12 +72,16 @@ class Encryption { } Future handleToDeviceEvent(ToDeviceEvent event) async { - if (['m.room_key', 'm.room_key_request', 'm.forwarded_room_key'] - .contains(event.type)) { - // a new room key or thelike. We need to handle this asap, before other + if (event.type == 'm.room_key') { + // a new room key. We need to handle this asap, before other // events in /sync are handled await keyManager.handleToDeviceEvent(event); } + if (['m.room_key_request', 'm.forwarded_room_key'].contains(event.type)) { + // "just" room key request things. We don't need these asap, so we handle + // them in the background + unawaited(keyManager.handleToDeviceEvent(event)); + } if (event.type.startsWith('m.key.verification.')) { // some key verification event. No need to handle it now, we can easily // do this in the background diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index e60cacb..9460827 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -123,6 +123,8 @@ class KeyManager { json.encode(content), json.encode({}), ); + // Note to self: When adding key-backup that needs to be unawaited(), else + // we might accidentally end up with http requests inside of the sync loop // TODO: somehow try to decrypt last message again final room = client.getRoomById(roomId); if (room != null) {