getUserDeviceKeys method

  1. @override
Future<Map<String, DeviceKeysList>> getUserDeviceKeys(
  1. Client client
)
override

Implementation

@override
Future<Map<String, DeviceKeysList>> getUserDeviceKeys(Client client) =>
    runBenchmarked<Map<String, DeviceKeysList>>(
        'Get all user device keys from Hive', () async {
      final deviceKeysOutdated = _userDeviceKeysOutdatedBox.keys;
      if (deviceKeysOutdated.isEmpty) {
        return {};
      }
      final res = <String, DeviceKeysList>{};
      for (final userId in deviceKeysOutdated) {
        final deviceKeysBoxKeys = _userDeviceKeysBox.keys.where((tuple) {
          final tupleKey = MultiKey.fromString(tuple);
          return tupleKey.parts.first == userId;
        });
        final crossSigningKeysBoxKeys =
            _userCrossSigningKeysBox.keys.where((tuple) {
          final tupleKey = MultiKey.fromString(tuple);
          return tupleKey.parts.first == userId;
        });
        res[userId] = DeviceKeysList.fromDbJson(
            {
              'client_id': client.id,
              'user_id': userId,
              'outdated': await _userDeviceKeysOutdatedBox.get(userId),
            },
            await Future.wait(deviceKeysBoxKeys.map((key) async =>
                convertToJson(await _userDeviceKeysBox.get(key)))),
            await Future.wait(crossSigningKeysBoxKeys.map((key) async =>
                convertToJson(await _userCrossSigningKeysBox.get(key)))),
            client);
      }
      return res;
    }, _userDeviceKeysBox.keys.length);