updateWithRequestLocationAcknowledge method

Future updateWithRequestLocationAcknowledge(
  1. LocationNotificationModel originalLocationNotificationModel, {
  2. bool rePrompt = false,
})

Updates originally created locationNotificationModel with originalLocationNotificationModel data If rePrompt is true, then will show dialog box on receiver's side.

Implementation

Future updateWithRequestLocationAcknowledge(
    LocationNotificationModel originalLocationNotificationModel,
    {bool rePrompt = false}) async {
  try {
    var locationNotificationModel = LocationNotificationModel.fromJson(
        jsonDecode(
            LocationNotificationModel.convertLocationNotificationToJson(
                originalLocationNotificationModel)));

    var atkeyMicrosecondId = locationNotificationModel.key!
        .split('requestlocation-')[1]
        .split('@')[0];

    var response =
        await AtLocationNotificationListener().atClientInstance!.getKeys(
              regex: 'requestlocation-$atkeyMicrosecondId',
            );

    var key = getAtKey(response[0]);

    if ((locationNotificationModel.isAccepted) &&
        (locationNotificationModel.from != null) &&
        (locationNotificationModel.to != null)) {
      key.metadata!.ttl = locationNotificationModel.to!
              .difference(locationNotificationModel.from!)
              .inMinutes *
          60000;
      key.metadata!.ttr = locationNotificationModel.to!
              .difference(locationNotificationModel.from!)
              .inMinutes *
          60000;
      key.metadata!.expiresAt = locationNotificationModel.to;
    }

    locationNotificationModel.isAcknowledgment = true;
    locationNotificationModel.rePrompt = rePrompt;

    var notification =
        LocationNotificationModel.convertLocationNotificationToJson(
            locationNotificationModel);
    var result;
    result = await AtLocationNotificationListener().atClientInstance!.put(
          key,
          notification,
          isDedicated: MixedConstants.isDedicated,
        );

    if (result) {
      if (MixedConstants.isDedicated) {
        await SyncSecondary().callSyncSecondary(SyncOperation.syncSecondary);
      }
      KeyStreamService()
          .mapUpdatedLocationDataToWidget(locationNotificationModel);
    }

    print('update result - $result');

    return result;
  } catch (e) {
    return false;
  }
}