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) {
    List<AtKey>? scanList;
    try {
      scanList = await atClient!.getAtKeys(regex: atKey.key);
    } on KeyNotFoundException {
      logger.info('${atKey.key} does not exist in keystore');
    } on AtClientException {
      logger.info('${atKey.key} does not exist in keystore');
    }
    atKey = (scanList != null && scanList.isNotEmpty)
        ? _formAtKeyFromScanKeys(scanList[0])
        : atKey;
  }
  AtValue? atValue;
  atValue = await _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 _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 _get(newAtKey);
    if (atValue?.value != null) await atClient!.delete(atKey);
  }
  AtGroup? 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;
}