mapUpdatedLocationDataToWidget method

Future<void> mapUpdatedLocationDataToWidget(
  1. LocationNotificationModel locationData, {
  2. bool shouldCheckForTimeChanges = false,
})

Updates any KeyLocationModel data for updated data

Implementation

Future<void> mapUpdatedLocationDataToWidget(
    LocationNotificationModel locationData,
    {bool shouldCheckForTimeChanges = false}) async {
  /// so, that we don't add any expired event
  if (isPastNotification(locationData)) {
    return;
  }

  String newLocationDataKeyId;
  if (locationData.key!.contains(MixedConstants.SHARE_LOCATION)) {
    newLocationDataKeyId =
        locationData.key!.split('sharelocation-')[1].split('@')[0];
  } else {
    newLocationDataKeyId =
        locationData.key!.split('requestlocation-')[1].split('@')[0];
  }

  //// If we want to add any such notification that is not in the list, but we get an update
  var _locationDataNotPresent = true;

  for (var i = 0; i < allLocationNotifications.length; i++) {
    if (allLocationNotifications[i]
        .locationNotificationModel!
        .key!
        .contains(newLocationDataKeyId)) {
      allLocationNotifications[i].locationNotificationModel = locationData;
      _locationDataNotPresent = false;
    }
  }

  if (_locationDataNotPresent) {
    addDataToList(locationData);
  }
  notifyListeners();

  if (shouldCheckForTimeChanges) {
    SendLocationNotification()
        .allAtsignsLocationData[locationData.receiver!]!
        .locationSharingFor[trimAtsignsFromKey(locationData.key!)]!
        .from = locationData.from;

    SendLocationNotification()
        .allAtsignsLocationData[locationData.receiver!]!
        .locationSharingFor[trimAtsignsFromKey(locationData.key!)]!
        .to = locationData.to;

    SendLocationNotification()
        .sendLocationAfterDataUpdate([locationData.receiver!]);

    return;
  }

  // Update location sharing
  if ((locationData.isSharing) && (locationData.isAccepted)) {
    if (locationData.atsignCreator == currentAtSign) {
      var _tempLocationDataModel = SendLocationNotification()
          .locationNotificationModelToLocationDataModel(locationData);

      if (SendLocationNotification()
          .ifLocationDataAlreadyExists(_tempLocationDataModel)) {
        SendLocationNotification()
            .allAtsignsLocationData[locationData.receiver!]!
            .locationSharingFor = {
          ...SendLocationNotification()
              .allAtsignsLocationData[locationData.receiver!]!
              .locationSharingFor,
          ..._tempLocationDataModel.locationSharingFor,
        };

        SendLocationNotification()
            .sendLocationAfterDataUpdate([locationData.receiver!]);
      } else {
        SendLocationNotification().addMember(_tempLocationDataModel);
      }
    }
  } else {
    if (compareAtSign(locationData.atsignCreator!, currentAtSign!)) {
      //// ifLocationDataAlreadyExists remove
      SendLocationNotification().removeMember(
          locationData.key!, [locationData.receiver!],
          isExited: locationData.isExited,
          isAccepted: locationData.isAccepted,
          isSharing: locationData.isSharing);
      //// Else add it
    }
  }
}