make sure that no http requests are done inside of /sync

This commit is contained in:
Sorunome 2020-07-26 07:54:03 +02:00
parent 3fae58439b
commit 14c8377a2f
No known key found for this signature in database
GPG key ID: B19471D07FC9BE9C
2 changed files with 9 additions and 3 deletions

View file

@ -72,12 +72,16 @@ class Encryption {
} }
Future<void> handleToDeviceEvent(ToDeviceEvent event) async { Future<void> handleToDeviceEvent(ToDeviceEvent event) async {
if (['m.room_key', 'm.room_key_request', 'm.forwarded_room_key'] if (event.type == 'm.room_key') {
.contains(event.type)) { // a new room key. We need to handle this asap, before other
// a new room key or thelike. We need to handle this asap, before other
// events in /sync are handled // events in /sync are handled
await keyManager.handleToDeviceEvent(event); 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.')) { if (event.type.startsWith('m.key.verification.')) {
// some key verification event. No need to handle it now, we can easily // some key verification event. No need to handle it now, we can easily
// do this in the background // do this in the background

View file

@ -123,6 +123,8 @@ class KeyManager {
json.encode(content), json.encode(content),
json.encode({}), 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 // TODO: somehow try to decrypt last message again
final room = client.getRoomById(roomId); final room = client.getRoomById(roomId);
if (room != null) { if (room != null) {