getUserDeviceKeys method
Implementation
@override
Future<Map<String, DeviceKeysList>> getUserDeviceKeys(Client client) =>
runBenchmarked<Map<String, DeviceKeysList>>(
'Get all user device keys from store', () async {
final deviceKeysOutdated =
await _userDeviceKeysOutdatedBox.getAllKeys();
if (deviceKeysOutdated.isEmpty) {
return {};
}
final res = <String, DeviceKeysList>{};
final userDeviceKeysBoxKeys = await _userDeviceKeysBox.getAllKeys();
final userCrossSigningKeysBoxKeys =
await _userCrossSigningKeysBox.getAllKeys();
for (final userId in deviceKeysOutdated) {
final deviceKeysBoxKeys = userDeviceKeysBoxKeys.where((tuple) {
final tupleKey = TupleKey.fromString(tuple);
return tupleKey.parts.first == userId;
});
final crossSigningKeysBoxKeys =
userCrossSigningKeysBoxKeys.where((tuple) {
final tupleKey = TupleKey.fromString(tuple);
return tupleKey.parts.first == userId;
});
final childEntries = await Future.wait(
deviceKeysBoxKeys.map(
(key) async {
final userDeviceKey = await _userDeviceKeysBox.get(key);
if (userDeviceKey == null) return null;
return copyMap(userDeviceKey);
},
),
);
final crossSigningEntries = await Future.wait(
crossSigningKeysBoxKeys.map(
(key) async {
final crossSigningKey = await _userCrossSigningKeysBox.get(key);
if (crossSigningKey == null) return null;
return copyMap(crossSigningKey);
},
),
);
res[userId] = DeviceKeysList.fromDbJson(
{
'client_id': client.id,
'user_id': userId,
'outdated': await _userDeviceKeysOutdatedBox.get(userId),
},
childEntries
.where((c) => c != null)
.toList()
.cast<Map<String, dynamic>>(),
crossSigningEntries
.where((c) => c != null)
.toList()
.cast<Map<String, dynamic>>(),
client);
}
return res;
});