removeMember method

Future<void> removeMember(
  1. String inviteId,
  2. List<String> atsignsToRemove, {
  3. bool isSharing = false,
  4. required bool isExited,
  5. required bool isAccepted,
})

removes a inviteId LocationDataModel from atsignsToRemove of allAtsignsLocationData.

Implementation

Future<void> removeMember(String inviteId, List<String> atsignsToRemove,
    {bool isSharing = false,
    required bool isExited,
    required bool isAccepted}) async {
  inviteId = trimAtsignsFromKey(inviteId);

  List<String> updatedAtsigns = [], atsignsToDelete = [];
  allAtsignsLocationData.forEach((key, value) {
    for (var atsignToRemove in atsignsToRemove) {
      if ((compareAtSign(key, atsignToRemove)) &&
          (allAtsignsLocationData[key]?.locationSharingFor[inviteId] !=
              null)) {
        allAtsignsLocationData[key]
            ?.locationSharingFor[inviteId]!
            .isAccepted = isAccepted;
        allAtsignsLocationData[key]?.locationSharingFor[inviteId]!.isSharing =
            isSharing;
        allAtsignsLocationData[key]?.locationSharingFor[inviteId]!.isExited =
            isExited;

        updatedAtsigns.add(key);

        // .remove(inviteId);
        // if (allAtsignsLocationData[key]?.locationSharingFor.isEmpty ??
        //     false) {
        //   atsignsToDelete.add(key);
        // } else {
        // so that we dont update and delete the same key
        // updatedAtsigns.add(key);
        // }
      }
    }
  });
  if (updatedAtsigns.isNotEmpty) {
    await sendLocationAfterDataUpdate(updatedAtsigns);
  }

  if (atsignsToDelete.isNotEmpty) {
    await sendNull(atsignsToDelete);
  }
}