shareLocationAcknowledgment method

Future<bool> shareLocationAcknowledgment(
  1. LocationNotificationModel originalLocationNotificationModel,
  2. bool isAccepted
)

Sends a 'sharelocationacknowledged' key to originalLocationNotificationModel.atsignCreator with isAccepted as isAccepted

Implementation

Future<bool> shareLocationAcknowledgment(
    LocationNotificationModel originalLocationNotificationModel,
    bool isAccepted) async {
  try {
    var locationNotificationModel = LocationNotificationModel.fromJson(
        jsonDecode(
            LocationNotificationModel.convertLocationNotificationToJson(
                originalLocationNotificationModel)));
    var atkeyMicrosecondId = locationNotificationModel.key!
        .split('sharelocation-')[1]
        .split('@')[0];
    var atKey = newAtKey(-1, 'sharelocationacknowledged-$atkeyMicrosecondId',
        locationNotificationModel.atsignCreator);
    locationNotificationModel.isAccepted = isAccepted;
    locationNotificationModel.isExited = !isAccepted;

    var result = await NotifyAndPut().notifyAndPut(
      atKey,
      LocationNotificationModel.convertLocationNotificationToJson(
          locationNotificationModel),
    );
    _logger.finer('sendLocationNotificationAcknowledgment:$result');
    if (result) {
      CustomToast().show('Request to update data is submitted',
          AtLocationNotificationListener().navKey.currentContext,
          isSuccess: true);
      KeyStreamService().updatePendingStatus(locationNotificationModel);
    } else {
      CustomToast().show('Something went wrong , please try again.',
          AtLocationNotificationListener().navKey.currentContext,
          isError: true);
    }
    return result;
  } catch (e) {
    CustomToast().show('Something went wrong , please try again.',
        AtLocationNotificationListener().navKey.currentContext,
        isError: true);

    _logger.severe('sending share awk failed $e');
    return false;
  }
}