deleteMembers method

  1. @override
Future<bool> deleteMembers(
  1. Set<AtContact> atContacts,
  2. AtGroup? atGroup
)

takes Set of AtContacts as an input and deletes the contacts to the group members on success return true otherwise false

Implementation

@override
Future<bool> deleteMembers(
    Set<AtContact> atContacts, AtGroup? atGroup) async {
  if (atContacts.isEmpty || atGroup == null) {
    return false;
  }
  if (atGroup.groupId == null) {
    throw GroupNotExistsException('Group ID is null');
  }
  var atKey = _formKey(KeyType.group, key: atGroup.groupId!);
  var members = atGroup.members;
  for (var atContact in atContacts) {
    var contactName = atContact.atSign;
    members!.removeWhere((contact) => (contact.atSign == contactName));
  }
  atGroup.members = members;
  atGroup.updatedBy = AtUtils.fixAtSign(atSign);
  atGroup.updatedOn = DateTime.now();
  var json = atGroup.toJson();
  var value = jsonEncode(json);
  return await atClient!.put(atKey, value);
}