deleteEvent function

Future<bool> deleteEvent(
  1. String key
)

This method deletes an event from the remote database using the provided event key It retrieves the event data associated with the key and checks if the current user is the creator of the event If the current user is not the creator, it throws an exception The method returns true if the event deletion is successful; otherwise, it returns false

Implementation

Future<bool> deleteEvent(String key) async {
  String? regexKey, currentAtsign;
  EventNotificationModel? eventData;
  currentAtsign = EventService().atClientManager.atClient.getCurrentAtSign();
  regexKey = await getRegexKeyFromKey(key);
  if (regexKey == null) {
    throw Exception('Event key not found');
  }
  eventData = await getValue(regexKey);
  print('eventData to delete:$eventData');

  if (eventData!.atsignCreator != currentAtsign) {
    throw Exception('Only creator can delete the event');
  }

  try {
    var atKey = EventService().getAtKey(regexKey);
    var result = await EventService().atClientManager.atClient.delete(atKey);
    // ignore: unnecessary_null_comparison
    if (result != null && result) {}
    return result;
  } catch (e) {
    return false;
  }
}