update method

VCalendar update({
  1. Method? method,
  2. EventStatus? eventStatus,
  3. String? comment,
  4. List<AttendeeProperty>? addAttendees,
  5. List<String>? addAttendeeEmails,
  6. List<AttendeeProperty>? removeAttendees,
  7. List<String>? removeAttendeesEmails,
  8. bool attendeeFilter(
    1. AttendeeProperty
    )?,
  9. String? description,
})

Prepares an update of this calendar.

An organizer can use this to send an updated version around.

Creates a copy with an updated VEvent.timeStamp, an increased VEvent.sequence and the method set to Method.request.

All parameters are optional and are applied as a convenience.

Implementation

VCalendar update({
  Method? method,
  EventStatus? eventStatus,
  String? comment,
  List<AttendeeProperty>? addAttendees,
  List<String>? addAttendeeEmails,
  List<AttendeeProperty>? removeAttendees,
  List<String>? removeAttendeesEmails,
  bool Function(AttendeeProperty)? attendeeFilter,
  String? description,
}) {
  final copied = copy() as VCalendar;
  if (method != null) {
    copied.method = method;
  }
  final event =
      copied.children.firstWhereOrNull((ev) => ev is VEvent) as VEvent?;
  if (event != null) {
    final sequence = event.sequence;
    event
      ..sequence = sequence != null ? sequence + 1 : 1
      ..timeStamp = DateTime.now();
    if (eventStatus != null) {
      event.status = eventStatus;
    }
    if (comment != null) {
      event.comment = comment;
    }
    if (addAttendees != null) {
      event.properties.addAll(addAttendees);
    }
    if (addAttendeeEmails != null) {
      for (final email in addAttendeeEmails) {
        event.addAttendee(AttendeeProperty.create(attendeeEmail: email)!);
      }
    }
    if (removeAttendees != null) {
      for (final prop in removeAttendees) {
        event.removeAttendeeWithUri(prop.uri);
      }
    }
    if (removeAttendeesEmails != null) {
      removeAttendeesEmails.forEach(event.removeAttendeeWithEmail);
    }
    if (attendeeFilter != null) {
      final attendees = event.attendees;
      for (final attendee in attendees) {
        if (!attendeeFilter(attendee)) {
          event.removeAttendee(attendee);
        }
      }
    }
    if (description != null) {
      event.description = description;
    }
  }

  return copied;
}