removeUnusedNamedSecretStorageKeys method

Future<void> removeUnusedNamedSecretStorageKeys(
  1. String name
)

Implementation

Future<void> removeUnusedNamedSecretStorageKeys(String name) async {
  if (name.isEmpty) return;
  const prefix = 'm.secret_storage.key.';
  final usedKeyIds =
      analyzeEncryptedSecrets().values.expand((s) => s).toSet();
  final entries = client.accountData.entries.toList(growable: false);
  for (final entry in entries) {
    if (!entry.key.startsWith(prefix)) continue;
    final keyId = entry.key.substring(prefix.length);
    if (entry.value.content['name'] != name) continue;
    if (usedKeyIds.contains(keyId)) continue;
    await _setAccountDataAndWaitForSync(
      EventTypes.secretStorageKey(keyId),
      {},
    );
  }
}