From 86038f8c944c939e72022849aa18812254e8335c Mon Sep 17 00:00:00 2001 From: Krille Date: Tue, 4 Feb 2025 09:26:26 +0100 Subject: [PATCH] refactor: Use .toSet() instead of Set.from() When using Set.from() then it becomes a Set of dynamics which disables the Type checking. By just changing this to .toSet() it keeps the type. --- lib/encryption/key_manager.dart | 44 +++++++++++++++------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index 5c3df9c1..3d18032d 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -357,8 +357,8 @@ class KeyManager { final newDeviceKeys = await room.getUserDeviceKeys(); final newDeviceKeyIds = _getDeviceKeyIdMap(newDeviceKeys); // first check for user differences - final oldUserIds = Set.from(sess.devices.keys); - final newUserIds = Set.from(newDeviceKeyIds.keys); + final oldUserIds = sess.devices.keys.toSet(); + final newUserIds = newDeviceKeyIds.keys.toSet(); if (oldUserIds.difference(newUserIds).isNotEmpty) { // a user left the room, we must wipe the session wipe = true; @@ -375,19 +375,17 @@ class KeyManager { // we also know that all the old user IDs appear in the old one, else we have already wiped the session for (final userId in oldUserIds) { final oldBlockedDevices = sess.devices.containsKey(userId) - ? Set.from( - sess.devices[userId]!.entries - .where((e) => e.value) - .map((e) => e.key), - ) + ? sess.devices[userId]!.entries + .where((e) => e.value) + .map((e) => e.key) + .toSet() : {}; final newBlockedDevices = newDeviceKeyIds.containsKey(userId) - ? Set.from( - newDeviceKeyIds[userId]! - .entries - .where((e) => e.value) - .map((e) => e.key), - ) + ? newDeviceKeyIds[userId]! + .entries + .where((e) => e.value) + .map((e) => e.key) + .toSet() : {}; // we don't really care about old devices that got dropped (deleted), we only care if new ones got added and if new ones got blocked // check if new devices got blocked @@ -397,19 +395,17 @@ class KeyManager { } // and now add all the new devices! final oldDeviceIds = sess.devices.containsKey(userId) - ? Set.from( - sess.devices[userId]!.entries - .where((e) => !e.value) - .map((e) => e.key), - ) + ? sess.devices[userId]!.entries + .where((e) => !e.value) + .map((e) => e.key) + .toSet() : {}; final newDeviceIds = newDeviceKeyIds.containsKey(userId) - ? Set.from( - newDeviceKeyIds[userId]! - .entries - .where((e) => !e.value) - .map((e) => e.key), - ) + ? newDeviceKeyIds[userId]! + .entries + .where((e) => !e.value) + .map((e) => e.key) + .toSet() : {}; // check if a device got removed