deleteKey method

Future<bool> deleteKey(
  1. LocationNotificationModel locationNotificationModel
)

Deletes originally created locationNotificationModel notification

Implementation

Future<bool> deleteKey(
    LocationNotificationModel locationNotificationModel) async {
  try {
    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;

    var result = await AtClientManager.getInstance().atClient.delete(
          key,
        );

    /// remove notification
    key.sharedWith = locationNotificationModel.receiver;
    if (!key.sharedWith!.contains('@')) {
      key.sharedWith = '@${key.sharedWith!}';
    }
    var resultForNotification =
        await AtClientManager.getInstance().atClient.delete(
              key,
            );
    _logger.finer(
        'deleteKey share location resultForNotification $resultForNotification');

    ///

    if (result) {
      KeyStreamService().removeData(key.key);
    }
    return result;
  } catch (e) {
    _logger.severe('error in deleting key $e');
    return false;
  }
}