updateWithShareLocationAcknowledge method

Future<bool> updateWithShareLocationAcknowledge(
  1. LocationNotificationModel originalLocationNotificationModel, {
  2. bool? isSharing,
  3. bool rePrompt = false,
})

Updates originally created locationNotificationModel with originalLocationNotificationModel data

Implementation

Future<bool> updateWithShareLocationAcknowledge(
    LocationNotificationModel originalLocationNotificationModel,
    {bool? isSharing,
    bool rePrompt = false}) async {
  try {
    var locationNotificationModel = LocationNotificationModel.fromJson(
        jsonDecode(
            LocationNotificationModel.convertLocationNotificationToJson(
                originalLocationNotificationModel)));

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

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

    var key = getAtKey(response[0]);

    locationNotificationModel.isAcknowledgment = true;
    locationNotificationModel.rePrompt =
        rePrompt; // Dont show dialog box again

    if (isSharing != null) locationNotificationModel.isSharing = isSharing;

    var notification =
        LocationNotificationModel.convertLocationNotificationToJson(
            locationNotificationModel);

    if ((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;
    }

    var 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) {
    print('update share location failed $e');

    return false;
  }
}