getCached method
Implementation
Future<String?> getCached(String type) async {
if (client.database == null) {
return null;
}
// check if it is still valid
final keys = keyIdsFromType(type);
if (keys == null) {
return null;
}
bool isValid(SSSSCache dbEntry) =>
keys.contains(dbEntry.keyId) &&
dbEntry.ciphertext != null &&
dbEntry.keyId != null &&
client.accountData[type]?.content
.tryGetMap<String, Object?>('encrypted')
?.tryGetMap<String, Object?>(dbEntry.keyId!)
?.tryGet<String>('ciphertext') ==
dbEntry.ciphertext;
final fromCache = _cache[type];
if (fromCache != null && isValid(fromCache)) {
return fromCache.content;
}
final ret = await client.database?.getSSSSCache(type);
if (ret == null) {
return null;
}
if (isValid(ret)) {
_cache[type] = ret;
return ret.content;
}
return null;
}