deleteEvent function
Implementation
Future<bool> deleteEvent(String key) async {
String? regexKey, currentAtsign;
EventNotificationModel? eventData;
currentAtsign = EventService().atClientInstance!.currentAtSign;
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().atClientInstance!.delete(atKey);
// ignore: unnecessary_null_comparison
if (result != null && result) {
// EventService().allEvents.removeWhere((element) => element.key == key);
// EventService().eventListSink.add(EventService().allEvents);
}
return result;
} catch (e) {
return false;
}
}