listGroupNames method

  1. @override
Future<List<String?>> listGroupNames()

fetches all the group names as a list on success return List of Group names otherwise []

Implementation

@override
Future<List<String?>> listGroupNames() async {
  var atKey = _formKey(KeyType.groupList, isGet: true);
  if (_regexType == RegexType.all) {
    var scanList = await atClient!.getAtKeys(regex: atKey.key);
    atKey = scanList.isNotEmpty ? _formAtKeyFromScanKeys(scanList[0]) : atKey;
  }
  var result = await atClient!.get(atKey);

  //check for old key if new key data is not present.
  if (result.value == null) {
    atKey = _formKey(KeyType.groupList, isOld: true);
    result = await atClient!.get(atKey);
  }

  //migrate key to new keyformat.
  if (result.value != null && _isOldKey(atKey)) {
    var newAtKey = _formKey(
      KeyType.groupList,
    );
    await atClient!.put(newAtKey, result.value);
    result = await atClient!.get(newAtKey);
    if (result.value != null) await atClient!.delete(atKey);
  }
  // get name from AtGroupBasicInfo for all the groups.
  List<dynamic>? list = [];
  list = (result.value != null) ? jsonDecode(result.value) : [];
  list = List<String>.from(list!);
  var groupNames = <String?>[];
  list.forEach((group) {
    var groupInfo = AtGroupBasicInfo.fromJson(jsonDecode(group));
    groupNames.add(groupInfo.atGroupName);
  });
  return groupNames;
}