scanAndGet method

Future<AtFollowsValue> scanAndGet(
  1. String regex
)

Returns AtFollowsValue after scan with regex, fetching data for that key.

Implementation

Future<AtFollowsValue> scanAndGet(String regex) async {
  var scanKey = await AtClientManager.getInstance()
      .atClient
      .getAtKeys(regex: regex)
      .timeout(Duration(seconds: AppConstants.responseTimeLimit),
          onTimeout: () => _onTimeOut());
  int index = scanKey.length - 1;
  for (int i = 0; i < scanKey.length; i++) {
    if (scanKey[i].key.endsWith("self.at_follows") &&
        scanKey[i].namespace == "wavi" &&
        scanKey[i].sharedWith == null) {
      index = i;
    }
  }
  AtFollowsValue value =
      scanKey.isNotEmpty ? await this.get(scanKey[index]) : AtFollowsValue();
  //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.value != null) {
      await this.delete(scanKey[0]);
    }
  }
  return value;
}