cancelEventForAttendees method

AttendeeCancelResult cancelEventForAttendees({
  1. List<AttendeeProperty>? cancelledAttendees,
  2. List<String>? cancelledAttendeeEmails,
  3. String? comment,
})

Cancels this VCalendar event for the specified cancelledAttendees.

Organizers of an calendar event can cancel an event for attendees. You must either specify cancelledAttendees or cancelledAttendeeEmails. Compare cancelEvent in case you want to cancel the whole event

Implementation

AttendeeCancelResult cancelEventForAttendees({
  List<AttendeeProperty>? cancelledAttendees,
  List<String>? cancelledAttendeeEmails,
  String? comment,
}) {
  assert(
    cancelledAttendeeEmails != null || cancelledAttendees != null,
    'You must specify either cancelledAttendees or cancelledAttendeeEmails',
  );
  assert(
    !(cancelledAttendeeEmails != null && cancelledAttendees != null),
    'You must specify either cancelledAttendees or '
    'cancelledAttendeeEmails, but not both',
  );
  final attendeeChange = update(
    method: Method.cancel,
    comment: comment,
    attendeeFilter: (attendee) => cancelledAttendeeEmails != null
        ? cancelledAttendeeEmails.contains(attendee.email)
        : cancelledAttendees?.any((a) => a.uri == attendee.uri) ?? false,
  );
  final groupChange = copy() as VCalendar;
  final event = groupChange.event;
  if (event != null) {
    final attendees = cancelledAttendeeEmails != null
        ? event.attendees.where(
            (attendee) => cancelledAttendeeEmails.contains(attendee.email),
          )
        : event.attendees.where(
            (attendee) =>
                cancelledAttendees
                    ?.any((cancelled) => cancelled.uri == attendee.uri) ??
                false,
          );
    for (final attendee in attendees) {
      attendee
        ..rsvp = false
        ..role = Role.nonParticipant;
    }
  }

  return AttendeeCancelResult(attendeeChange, groupChange);
}