1 import { getAttendeeEmail } from '@proton/shared/lib/calendar/attendees';
2 import type { VcalVeventComponent } from '@proton/shared/lib/interfaces/calendar';
4 import type { InviteActions } from '../interfaces/Invite';
5 import { INVITE_ACTION_TYPES } from '../interfaces/Invite';
7 const { SEND_INVITATION, SEND_UPDATE, CHANGE_PARTSTAT, DECLINE_INVITATION, CANCEL_INVITATION } = INVITE_ACTION_TYPES;
9 export const extractInviteEmails = ({
14 inviteActions: InviteActions;
15 vevent?: VcalVeventComponent;
16 cancelVevent?: VcalVeventComponent;
18 const { type, addedAttendees, removedAttendees } = inviteActions;
19 const hasAddedAttendees = !!addedAttendees?.length;
20 const hasRemovedAttendees = !!removedAttendees?.length;
21 const invitedEmails = vevent?.attendee?.map((attendee) => getAttendeeEmail(attendee));
22 const addedEmails = addedAttendees?.map((attendee) => getAttendeeEmail(attendee));
23 const removedEmails = removedAttendees?.map((attendee) => getAttendeeEmail(attendee));
24 const cancelledEmails = cancelVevent?.attendee?.map((attendee) => getAttendeeEmail(attendee));
25 const organizerEmail = vevent?.organizer ? getAttendeeEmail(vevent.organizer) : undefined;
26 const emails: string[] = [];
28 if (type === SEND_INVITATION) {
29 if (!hasAddedAttendees && !hasRemovedAttendees && invitedEmails?.length) {
30 emails.push(...invitedEmails);
32 if (addedEmails?.length) {
33 emails.push(...addedEmails);
35 if (removedEmails?.length) {
36 emails.push(...removedEmails);
39 } else if (type === SEND_UPDATE) {
40 if (invitedEmails?.length) {
41 emails.push(...invitedEmails);
43 if (removedEmails?.length) {
44 emails.push(...removedEmails);
46 } else if (type === CANCEL_INVITATION) {
47 if (cancelledEmails?.length) {
48 emails.push(...cancelledEmails);
50 } else if ([CHANGE_PARTSTAT, DECLINE_INVITATION].includes(type)) {
52 emails.push(organizerEmail);