diff --git a/lib/src/client.dart b/lib/src/client.dart index 2938176..c8d752e 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -1729,6 +1729,16 @@ class Client { } } } else { + if (encrypted) { + // Create new sessions with devices if there is no existing session yet. + List deviceKeysWithoutSession = + List.from(deviceKeys); + deviceKeysWithoutSession.removeWhere((DeviceKeys deviceKeys) => + olmSessions.containsKey(deviceKeys.curve25519Key)); + if (deviceKeysWithoutSession.isNotEmpty) { + await startOutgoingOlmSessions(deviceKeysWithoutSession); + } + } for (int i = 0; i < deviceKeys.length; i++) { DeviceKeys device = deviceKeys[i]; if (!data["messages"].containsKey(device.userId)) { @@ -1736,14 +1746,6 @@ class Client { } if (encrypted) { - // Create new sessions with devices if there is no existing session yet. - List deviceKeysWithoutSession = - List.from(deviceKeys); - deviceKeysWithoutSession.removeWhere((DeviceKeys deviceKeys) => - olmSessions.containsKey(deviceKeys.curve25519Key)); - if (deviceKeysWithoutSession.isNotEmpty) { - await startOutgoingOlmSessions(deviceKeysWithoutSession); - } List existingSessions = olmSessions[device.curve25519Key]; if (existingSessions == null || existingSessions.isEmpty) continue;