scanAndGet method
Returns AtFollowsValue
after scan with regex
, fetching data for that key.
Implementation
Future<AtFollowsValue> scanAndGet(String regex) async {
var scanKey = await _atClientServiceInstance.atClient!
.getAtKeys(regex: regex)
.timeout(Duration(seconds: AppConstants.responseTimeLimit),
onTimeout: () => _onTimeOut());
AtFollowsValue value =
scanKey.isNotEmpty ? await this.get(scanKey[0]) : AtFollowsValue();
//migrates to newnamespace
if (scanKey.isNotEmpty &&
_isOldKey(scanKey[0].key) &&
value.value != null) {
var newKey = AtKey()..metadata = scanKey[0].metadata;
newKey.key = scanKey[0].key!.contains('following')
? AppConstants.followingKey
: AppConstants.followersKey;
await this.put(newKey, value.value);
value = await this.get(newKey);
if (value != null && value.value != null) {
await this.delete(scanKey[0]);
}
}
return value;
}