getGroup method

  1. @override
Future<AtGroup?> getGroup(
  1. String? groupId
)

takes groupName as an input and get the group details on success return AtGroup otherwise null

Implementation

@override
Future<AtGroup?> getGroup(String? groupId) async {
  if (groupId == null || groupId.isEmpty) {
    return null;
  }

  var atKey = _formKey(KeyType.group, key: groupId, isGet: true);
  if (_regexType == RegexType.all) {
    var scanList = await atClient!.getAtKeys(regex: atKey.key);
    atKey = scanList.isNotEmpty ? _formAtKeyFromScanKeys(scanList[0]) : atKey;
  }
  var atValue = await atClient!.get(atKey);
  //check for old key if new key data is not present.
  if (atValue.value == null) {
    atKey = _formKey(KeyType.group, key: groupId, isOld: true);
    atValue = await atClient!.get(atKey);
  }
  //migrate key to new keyformat.
  if (atValue.value != null && _isOldKey(atKey)) {
    var newAtKey = _formKey(KeyType.group, key: groupId);
    await atClient!.put(newAtKey, atValue.value);
    atValue = await atClient!.get(newAtKey);
    if (atValue.value != null) await atClient!.delete(atKey);
  }
  var group;
  if (atValue.value != null) {
    var value = atValue.value;
    value = value?.replaceAll('data:', '');
    if (value != null && value != 'null') {
      var json = jsonDecode(value);
      if (json != null) {
        group = AtGroup.fromJson(json);
      }
    }
  }

  return group;
}